Android:新浪微博拉起客户端分享——完美实现同时分享图片和文字(Intent.ACTION_SEND)
来源:互联网 发布:finale2016打谱软件 编辑:程序博客网 时间:2024/05/16 15:34
新浪微博拉起客户端分享——完美实现同时分享图片和文字(Intent.ACTION_SEND)
点击事件后处理:
private void share(String content, Uri uri){ if (AppUtils.isAppExist(mContext, "com.sina.weibo")) {Log.i("TAG", "----------------com.sina.weibo.ComposerDispatchActivity");Intent intent = new Intent(Intent.ACTION_SEND);intent.setPackage("com.sina.weibo"); //intent.setClassName("com.sina.weibo", "com.sina.weibo.ComposerDispatchActivity");if (uri == null ) {intent.setType("text/plain"); // 纯文本} else {File f = new File(“/mnt/sdcard/”);if (f != null && f.exists() && f.isFile()) {intent.setType("image/*");Uri u = Uri.fromFile(f);intent.putExtra(Intent.EXTRA_STREAM, u);}}intent.putExtra(Intent.EXTRA_SUBJECT, mTitle);intent.putExtra(Intent.EXTRA_TEXT, mShareDetail + "!点击:" + mWebUrl);//intent.putExtra("com.weibo.android.content", mTitle);//intent.putExtra("com.sina.weibo.android.content", mShareDetail + "!点击:" + mWebUrl);mContext.startActivity(intent);} else {Toast.makeText(ShareActivity.this, "您尚未安装新浪微博", Toast.LENGTH_SHORT).show();}}
简直把我坑惨了,一直以为通过系统的分享需要知道第三方接收action的类,本文对应的就是ComposerDispatchActivity,实际上是没有必要进行intent.setClassName("com.sina.weibo", "com.sina.weibo.ComposerDispatchActivity");这个方式来实现的,因为你不知道第三方接收的键值是什么,直接
Intent intent = new Intent(Intent.ACTION_SEND);intent.setPackage("com.sina.weibo");这样就搞定了!!!!
不过最好加上try catch,因为可能No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 pkg=com.sina.weibo (has clip) (has extras) }
如下:
if (AppUtils.isAppExist(mContext, "com.sina.weibo")) {//可能No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 pkg=com.sina.weibo (has clip) (has extras) }try {<pre name="code" class="javascript">Intent intent = new Intent(Intent.ACTION_SEND);intent.setPackage("com.sina.weibo"); //intent.setClassName("com.sina.weibo", "com.sina.weibo.ComposerDispatchActivity");if (uri == null ) {intent.setType("text/plain"); // 纯文本} else {File f = new File(“/mnt/sdcard/”);if (f != null && f.exists() && f.isFile()) {intent.setType("image/*");Uri u = Uri.fromFile(f);intent.putExtra(Intent.EXTRA_STREAM, u);}}intent.putExtra(Intent.EXTRA_SUBJECT, mTitle);intent.putExtra(Intent.EXTRA_TEXT, mShareDetail + "!点击:" + mWebUrl);//intent.putExtra("com.weibo.android.content", mTitle);//intent.putExtra("com.sina.weibo.android.content", mShareDetail + "!点击:" + mWebUrl);mContext.startActivity(intent);} catch (Exception e) {Toast.makeText(ShareActivity.this, "分享失败", Toast.LENGTH_SHORT).show();e.printStackTrace();}} else {Toast.makeText(ShareActivity.this, "您尚未安装新浪微博", Toast.LENGTH_SHORT).show();}
这样就防止异常了
转载注明出处:http://blog.csdn.net/zbjdsbj/article/details/41119683
0 0
- Android:新浪微博拉起客户端分享——完美实现同时分享图片和文字(Intent.ACTION_SEND)
- 完美实现同时分享图片和文字(Intent.ACTION_SEND)
- 完美实现同时分享图片和文字(Intent.ACTION_SEND)
- 完美实现同时分享图片和文字(Intent.ACTION_SEND)
- android 使用Intent.ACTION_SEND分享图片和文字内容(新浪微博,短信等)
- 使用Intent.ACTION_SEND分享图片和文字内容(新浪微博,短信等)
- Android 调用系统的分享[完美实现同时分享图片和文字]
- Intent 实现qq空间和新浪微博的文字和图片分享
- Android分享之Intent.ACTION_SEND分享(一)
- Android分享之Intent.ACTION_SEND分享(二)
- Android系统自带分享功能的实现(可同时分享文字和图片)
- Android系统自带分享功能的实现(可同时分享文字和图片)
- android调用系统分享实现朋友圈同时分享文字和图片(可多张)
- Android系统自带分享功能的实现(可同时分享文字和图片)
- Android系统自带分享功能的实现(可同时分享文字和图片)
- android利用Intent.ACTION_SEND实现简单分享功能
- 新浪微博。。openapi 分享 图片+ 文字
- Android使用Intent一键分享图片文字到腾讯、新浪、开心、微信等
- iOS协议
- 你当真(是时候抛弃Eclipse转向IntelliJ了)
- netperf 网络性能测量
- ADB端口被占用
- storyboard view之间传值swift
- Android:新浪微博拉起客户端分享——完美实现同时分享图片和文字(Intent.ACTION_SEND)
- utl_file包的使用
- 51单片机之大杂烩
- XCode 快捷键
- Eclipse中注释复用
- 在Java应用中使用BeanShell(2.0b41)的简单示例
- 关于block的实现和注意
- android enter 隐藏输入法
- JSP内置对象request中的getParameter()和getAttribute()方法的区别