Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing data on WhatsApp not working on android 11

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?

like image 427
Vishal Patel Avatar asked Jan 24 '23 15:01

Vishal Patel


1 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>
like image 157
Vishal Patel Avatar answered Feb 04 '23 15:02

Vishal Patel