问题分析:
1.微信已经不支持多图带入分享,通道已堵死,只能带入一张图片。
2.网上很多方法都能实现图片带入,进入页面后,不显示+号,无法添加更多图片。
错误示例:
错误示例 1
val shareIntent = Intent()
intent.component = ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI")
shareIntent.action = Intent.ACTION_SEND_MULTIPLE
shareIntent.type = "image/*"
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriList)
//shareIntent.putExtra(Intent.EXTRA_STREAM, imageUriList)
startActivity(shareIntent)
错误示例 2
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.component = ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI")
shareIntent.type = "image/*"
shareIntent.putExtra("Kdescription", "文字内容")
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUriList[0])
startActivity(intent)
进入后,不显示加+号,没法添加更多的图片,没有达到添加多图的效果。

解决方案:
1.先下载图片到本地,再获取到图片的Uri,注意此处Uri的格式。
错误示例:/storage/emulated/xxx
正确格式:content://media/external/images/media/227979
获取Uri方式:根据图片absolutePath获取Uri:
val imageUriList = mutableListOf<Uri>()
val array = fileList.map { it.absolutePath }.toTypedArray()
MediaScannerConnection.scanFile(mContext, array, null) { _, uri ->
imageUriList.add(uri)
if (imageUriList.size == fileList.size) {
runOnUiThread {
shareImageToWeixinCircle(imageUriList)
}
}
}
2.分享,注意页面名字ShareScreenToTimeLineUI,和上面的不同;传入文字和第一张图片Uri。
val shareIntent = Intent()
shareIntent.component = ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareScreenToTimeLineUI")
shareIntent.addCategory(Intent.CATEGORY_DEFAULT)
shareIntent.action = Intent.ACTION_VIEW
shareIntent.setDataAndType(imageUriList[0], "image/*")
shareIntent.putExtra("Kdescription", "test3")
val chooserIntent = Intent.createChooser(shareIntent, "多图分享")
3.分享成功效果,即带入文字和第一张图,也可添加图片。

网友评论