应用场景:某个手机阅读器程序,读者看到一篇 文章,觉得不错,想要与朋友分享  。
  应用展现:按手机的Menu键,弹出“分享”菜单,点击后显示一系列Android分享功能的方式(短信、E-mail等)  。
  背景知识:Android上不同程序里面的Activity之间可以互相调用  。你可以在自己的程序中,调用短信程序,发送一条短信  。调用的方式就是向系统提出请求,系统会去调用适当的程序Activity。
  以下是Android分享功能实现源代码:

import java.util.List;  
import android.app.Activity;  
import android.content.Intent;  
import android.content.pm.PackageManager;  
import android.content.pm.ResolveInfo;  
import android.os.Bundle;  
import android.view.Menu;  
import android.view.MenuItem;  
public class Main extends Activity {  
@Override  
public void onCreate(Bundle savedInstanceState) {  
  super.onCreate(savedInstanceState);  
  setContentView(R.layout.main);   
} 
/* 创建菜单 */  
public boolean onCreateOptionsMenu(Menu menu) {  
  menu.add(0,0,0,"分享");   
  return true;  
}  
public boolean onOptionsItemSelected(MenuItem item){  
  switch (item.getItemId()){  
  case 0:  
    Intent intent=new Intent(Intent.ACTION_SEND);  
    //intent.setType("text/plain");  //纯文本
    /*图片分享
    it.setType("image/png");
     //添加图片
      File f = new File(Environment.getExternalStorageDirectory()+"/name.png");
       
      Uri uri = Uri.fromFile(f);
      intent.putExtra(Intent.EXTRA_STREAM, uri);
     */

    intent.putExtra(Intent.EXTRA_SUBJECT, "分享");  
    intent.putExtra(Intent.EXTRA_TEXT, "I would like to share this with you...");  
    startActivity(Intent.createChooser(intent, getTitle()));  
    return true;  
  }  
  return false;  
}  
}




我实现的看下面:


Intent intent=new Intent(Intent.ACTION_SEND);
intent.setType("image/*");//intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "好友推荐");
intent.putExtra(Intent.EXTRA_TEXT, "嗨,我正在使用众意彩购买彩票,你也来试试手气哈!");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, getTitle()));







Android 调用已安装市场,进行软件评分的功能实现


Uri uri = Uri.parse("market://details?id="+getPackageName());  
Intent intent = new Intent(Intent.ACTION_VIEW,uri);  
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
startActivity(intent);




分享:


Intent sendIntent = new Intent();  
sendIntent.setAction(Intent.ACTION_SEND);  
sendIntent.setType("text/*");  
sendIntent.putExtra(Intent.EXTRA_TEXT, contentEditText.getText().toString());  
startActivity(sendIntent);





使用ShareActionProvider分享数据


http://www.open-open.com/lib/view/open1455981263058.html



Google Android开发者文档系列之与其他应用程序交互(一)


http://www.open-open.com/lib/view/open1464679191635.html


  • android实现分享给好友功能_ide

  • 大小: 84.1 KB
  • 查看图片附件