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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With