在Android 11上,无法在WhatsApp上共享数据

5

在将我的项目升级到API 30后,我检查了通过意图分享WhatsApp数据在Android 11设备上不起作用,可能是由于Android 11中的包可见性

 val imgBitmapPath = MediaStore.Images.Media.insertImage(mContext.contentResolver, bitmap, "eVitalRx_Greetings_" + Calendar.getInstance().getTime(), null)
    val imgUri = Uri.parse(imgBitmapPath)
    val whatsappIntent = Intent(Intent.ACTION_SEND)
    if (appInstalledOrNot(mContext, "com.whatsapp")) {
        whatsappIntent.setPackage("com.whatsapp")
    } else {
        whatsappIntent.setPackage("com.whatsapp.w4b")
    }
    whatsappIntent.putExtra(Intent.EXTRA_TEXT, msg)
    whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri)
    whatsappIntent.type = "image/jpeg"
    whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
    try {
        mContext.startActivity(whatsappIntent)
    } catch (ex: ActivityNotFoundException) {
        Toast.makeText(mContext, "Whatsapp not installed", Toast.LENGTH_LONG).show()
    }

在安卓11设备上,显示消息"Whatsapp未安装"。是否有人有解决方案?

请查看下面的答案,兄弟。 - Vishal Patel
2个回答

9

最终,通过花时间阅读原始文档和其他链接,我得到了一个答案。

如果你想与其他应用程序进行任何形式的交互,你必须将包名添加到清单文件中。

 <queries>
       
        <package android:name="com.whatsapp" />
        <package android:name="com.whatsapp.w4b" />
       
 </queries>

你能详细说明一下吗? - Victory
请看以下链接:https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9 - Vishal Patel
你能够分享图片到WhatsApp吗? - Victory
3
从WhatsApp中收到错误提示:“不支持该文件格式”。 - Victory
这是文件问题,而不是共享问题。 - Vishal Patel
显示剩余3条评论

2

请在清单文件中添加以下内容,希望对您有所帮助。如果有效,请告诉我......<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接