怎么调用原生api给微信分享图片?

ayun00 2018-01-21 06:54:40
不想安装微信sdk , 我用其他的系统的相册都能给微信分享图片

我用一下的代码就不行, 分享到QQ没有问题, 微信上的就是一个没有后缀的文件, 打不开, 也不显示成图片


/**
* 分享功能
*
* @param context
* 上下文
* @param activityTitle
* Activity的名字
* @param msgTitle
* 消息标题
* @param msgText
* 消息内容
* @param imgPath
* 图片路径,不分享图片则传null
*/
public static void shareMsg(Context context, String activityTitle,
String msgTitle, String msgText, String imgPath) {
Intent intent = new Intent(Intent.ACTION_SEND);
if (imgPath == null || imgPath.equals("")) {
intent.setType("text/plain"); // 纯文本
} else {
File f = new File(imgPath);
if (f != null && f.exists() && f.isFile()) {
intent.setType("image/jpeg");
intent.putExtra("Kdescription", msgText);
Uri u = Uri.fromFile(f);
intent.putExtra(Intent.EXTRA_STREAM, u);
}
}
intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
intent.putExtra(Intent.EXTRA_TEXT, msgText);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(Intent.createChooser(intent, activityTitle));
}
...全文
792 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ayun00 2018-03-18
  • 打赏
  • 举报
回复
引用 1 楼 xiaohuh421 的回复:
https://www.zhihu.com/question/21288247 你看下这个帖子吧.
没用啊 那个帖子说是用Kdescription 我也用了啊
xiaohuh421 2018-01-22
  • 打赏
  • 举报
回复
https://www.zhihu.com/question/21288247 你看下这个帖子吧.

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧