Issue
I want to find email client installed on device and redirect email id on that application to send email message. It working fine below on android 10, but it not working in android 11. I found article regarding Package visibility filtering on Android 11. I didn't understand how to achieve this code functionality in android 11
request?.url.toString().startsWith("mailto:") -> {
val intent = Intent(Intent.ACTION_SENDTO)
intent.type = "message/rfc822"
intent.data = Uri.parse(request?.url.toString())
view?.context?.packageManager?.let { packageManager ->
if (packageManager.resolveActivity(intent, 0) != null) {
view.context?.startActivity(intent)
} else {
Log.E("Error to find ", "Email client")
}
}
}
It launch email client on lower than android 10 but unable to find email client in android 11. It shows always Error to find Email client. Can someone explain me in more detail how Package visibility filtering on Android 11 is working and can someone share some piece of code how to achieve this.
Solution
As your app targets Android 11 or higher and needs to interact with apps other than the ones that are visible automatically, add the queries element in your app's manifest file. Within the element, specify the other apps by package name, by intent signature, or by provider authority.
To view other packages, declare your app's need for increased package visibility using the element.
<manifest...>
<queries>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/jpeg" />
</intent>
</queries>
<application>
</application>
</manifest>
If your app might need to query or interact with all installed apps on a device (which is rare) the you can opt QUERY_ALL_PACKAGES permission introduced in Android 11.
If resolveActivity() return null then try with queryIntentActivities()
For more please refer : https://developer.android.com/training/package-visibility/declaring
Answered By - Jatin Sachdeva
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.