Sharing data on WhatsApp not working on android 11

Viewed 3813

After upgrading my project on API 30, I checked WhatsApp data sharing via intent not working on android 11 device May b due to Package visibility in 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()
    }

It displaying the message "Whatsapp not installed" in android 11 device.

Does anyone have a solution for this?

2 Answers

Finally, I got an answer by spending time with the original document and some other links.

if you want any kind of interaction with other apps you must add the package's name into the manifest file.

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

Add this in manifest file, I hope this helps you.Please Let me know if it works..... <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />

Related