通过Action_Send以及Intent.createChoose()调用系统分享功能时,是可以显示当前手机上已安装的能分享的客户端列表,当然,开发者也可以指定单独某一个平台来分享,代码如下:


public void showSinaDialog() {Intent weiboIntent = new Intent(Intent.ACTION_SEND);weiboIntent.setType("text/plain");PackageManager pm = getPackageManager();List matches = pm.queryIntentActivities(weiboIntent,PackageManager.MATCH_DEFAULT_ONLY);String packageName = "com.sina.weibo";ResolveInfo info = null;for (ResolveInfo each : matches) {String pkgName = each.activityInfo.applicationInfo.packageName;if (packageName.equals(pkgName)) {info = each;break;}}if (info == null) {new AlertDialog.Builder(MainActivity.this).setTitle("提示").setMessage("您还没有安装新浪微博,是否前往浏览器下载?").setPositiveButton("确定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {Uri uri = Uri.parse("http://app.sina.cn/appdetail.php?appID=84560");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);dialog.dismiss();}}).setNegativeButton("取消",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {// TODO Auto-generated method stubdialog.dismiss();}}).show();} else {weiboIntent.setClassName(packageName, info.activityInfo.name);weiboIntent.putExtra(Intent.EXTRA_TEXT, "分享内容"+ "http://blog.csdn.net/diyangxia");}startActivity(weiboIntent);}


这段代码实现的主要功能就是调用系统的分享功能,并根据新浪微博的包名"com.sina.weibo",直接跳转到新浪微博分享界面,而不用经过原来的分享列表,并且判断如果用户手机终端上没有安装新浪微博客户端,那么就跳转到浏览器的新浪微博下载页面,这个下载链接是新浪微博SDK中给出的。以此类推,如果想通过系统分享调用腾讯微博、人人等社交软件的分享,只要把com.sina.weibo的包名即可。

如果当前手机终端上未安装新浪微博客户端,则如图下所示:


       


如果已安装了新浪微博客户端,那么就会跳转到发博器界面,如图下所示:



当然也可以通过设置type和stream来分享图片,如下代码:

weiboIntent.setType("image/*");weiboIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("sdcard/appIcon.png"));//SD卡下图片的绝对路径


更多相关文章

  1. Android(安卓)Wake lock
  2. Android(安卓)文本转语音TextToSpeech (TTS)
  3. Android(安卓)Activity 生命周期(lifecycle)的研究
  4. Android(安卓)Logcat和Debug的使用
  5. android异常:Can not perform this action after onSaveInstanc
  6. Android应用程序安装与Launcher启动机制
  7. AIDL接口描述语言的使用
  8. Android实现QQ分享功能
  9. Android仿微信选择图片和拍照功能

随机推荐

  1. 太强了!这两款数据库中间件,完美解决 Sprin
  2. Spring Boot 项目中的三种多数据源方案,一
  3. 丢弃掉那些 BeanUtils 工具类吧,MapStruct
  4. 用 NodeJS 充分利用多核 CPU 的资源[每日
  5. IDEA + Spring Boot 的三种热加载方案,看
  6. 用 cURL 请求测试 ETag 浏览器缓存[每日
  7. 69.批量创建mysql用户
  8. 香~Spring Boot 应用也可以有注册中心。
  9. 香~Spring Boot 应用也可以有配置中心。
  10. W3C TPAC 大会上的 Service workers 内容