文章标题

本文介绍如何在安卓应用程序中实现将图片分享至微信的功能,包括分享给好友、添加到收藏及发送到朋友圈的不同方式,并提供了一段示例代码。

这里写图片描述

  • 直接分享到微信朋友

try {
       File file=new File(path);//path为要分享的图片路径
       Intent intent = new Intent();
        //分享至微信
        ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");
        intent.setComponent(comp);
        intent.setAction(Intent.ACTION_SEND);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setType("image/jpg");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
        ShowMessage("未检测到已安装微信");
    }

“com.tencent.mm.ui.tools.ShareImgUI”发送给联系人
“com.tencent.mm”,”com.tencent.mm.ui.tools.AddFavoriteUI”添加到收藏
“com.tencent.mm.ui.tools.ShareToTimeLineUI” 发送到朋友圈

  • 选择分享到可直接这样写
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享到"));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值