android系统自带分享图片到微信,通过intent和无障碍服务实现分享图片+文字到微信朋友圈...

本文介绍如何在Android系统中利用Intent和无障碍服务,实现在微信朋友圈分享图片和文字。详细讲解了相关代码实现,并提到了在Android 7.0上分享多图的常见问题及解决方案,以及针对微信6.6.7之后无法传递文字的辅助服务处理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

故事背景

在全民微商的大时代背景下,发圈是一个很重要的环节,基于这个需求,便出现了此篇文章

系统参数

硬件:小米手机6 MIUI9 安卓7.1.1

软件:微信6.6.7

预览

废话不多说,没图说个**

21fa3fdfd66367416db301b4f2603e35.gif

1533803880468975.gif

步骤

一、代码文件 WeiXinShareUtil

import android.content.ComponentName;

import android.content.Context;

import android.content.Intent;

import android.content.pm.PackageInfo;

import android.content.pm.PackageManager;

import android.net.Uri;

import android.widget.Toast;

import java.io.File;

/**

* Created by Administrator on 2015/6/24.

*/

public class WeiXinShareUtil {

public static void sharePhotoToWX(Context context, String text, String photoPath) {

if (!uninstallSoftware(context, "com.tencent.mm")) {

Toast.makeText(context, "微信没有安装!", Toast.LENGTH_SHORT).show();

return;

}

File file = new File(photoPath);

if (!file.exists()) {

String tip = "文件不存在";

Toast.makeText(context, tip + " path = " + photoPath, Toast.LENGTH_LONG).show();

return;

}

Intent intent = new Intent();

ComponentName componentName = new ComponentName("com.tencent.mm",

"com.tencent.mm.ui.tools.ShareToTimeLineUI");

intent.setComponent(componentName);

intent.setAction("android.intent.action.SEND");

intent.setType("image/*");

intent.putExtra("Kdescription", text);

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

context.startActivity(intent);

}

private static boolean uninstallSoftware(Context context, String packageName) {

PackageManager packageManager = context.getPackageManager();

try {

PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);

if (packageInfo != null) {

return true;

}

} catch (PackageManager.NameNotFoundException e) {

e.printStackTrace();

}

return false;

}

}

二、调用方式

WeiXinShareUtil.sharePhotoToWX(context, "test", photoPath);

第一个参数:上下文Context

第二次参数:你要分享的文字text

第三个参数:你要分享的图片路径photoPath

关于7.0分享多图出现的问题,可以参考这篇文章:使用原生intent分享图片获取资源失败问题

三、 补充说明:

安卓微信6.6.7之后,微信对'Kdescription'做了处理,所有文字带不过去了。

4004be6f89bd33d936a8261cd7d95a7f.png

image.png

四、微信 6.6.7不能传送文字的问题的解决方案

可以通过安卓的辅助服务功能,实现自动复制。就是监测微信发送朋友圈的页面->通过辅助服务把文字写入到Edittext。具体的代码已经放到下边的github仓库里了。

Github开源地址

先睹为快

apk下载地址:github

欢迎关注我的个人公众号(捯饬捯饬啥)

daochidaochisha

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值