美文网首页
Android微信7.0+多图分享,带入文字,显示+加号

Android微信7.0+多图分享,带入文字,显示+加号

作者: 行知_90 | 来源:发表于2020-04-21 16:26 被阅读0次

    问题分析:

    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)
    

    进入后,不显示加+号,没法添加更多的图片,没有达到添加多图的效果。


    3236225-a64891c537272bba.jpg

    解决方案:

    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.分享成功效果,即带入文字和第一张图,也可添加图片。


    3236225-9e56476c7ccbb792.jpg

    相关文章

      网友评论

          本文标题:Android微信7.0+多图分享,带入文字,显示+加号

          本文链接:https://www.haomeiwen.com/subject/pnbuihtx.html