I am trying to open Gmail from my app ( on click of button) . I am facing issue in android 11 only . Its not opening the Gmail . queryIntentActivities is returning empty list in this case.
Please help me how to fix this issue for android 11. Below is the code which i am using ..
val pkgManager = aContext.packageManager
val packages = pkgManager.queryIntentActivities(intent, 0)
if (!packages.isEmpty()) {
for (resolveInfo in packages) {
val packageName = resolveInfo.activityInfo.packageName
aEmailClientNames.add(resolveInfo.loadLabel(aContext.packageManager).toString())
aEmailClientIcons.add(resolveInfo.loadIcon(aContext.packageManager))
aEmailClientPackageNames.add(packageName)
}
packageManager.queryIntentActivities(intent, 0)
will return EMPTY list if your app is running ontargetSdkVersion 30
to resolved this issue you have to use<queries>
in menifest asqueryIntentActivities()
, are filtered based on the calling app's declaration.
Fix image capture + image upload to work with Android "scoped storage"
The issue can be related to new package visibility (https://developer.android.com/about/versions/11/privacy/package-visibility). After all updates (at least Android Studio 4.1) try to add in your manifest that shows what action is required in app. In my case problem disappears when adds.
IMAGE_CAPTURE for CAMERA, GET_CONTENT for GALLERY (to get files change mimeType if you want video), PICK for GALLERY (should change mimetype if u want video) CHOOSER for GALLERY (if someone have other image browsers)
You can also check in logcat what queries you have to add (should contains "BLOCKED" or "no permission".
Error is because ImagePickerModule
when you don't have permission in Intent with resolveActivity
returns null
(you can comment it to check better errors in startActivityForResult
)
Add <query>
in AndroidMenifest.xml
<manifest>
.....
.....
<queries>
<!-- Browser -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<!-- Camera -->
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
<!-- Gallery -->
<intent>
<action android:name="android.intent.action.GET_CONTENT" />
<data android:mimeType="image/*" />
</intent>
<intent>
<action android:name="android.intent.action.PICK" />
<data android:mimeType="image/*" />
</intent>
<intent>
<action android:name="android.intent.action.CHOOSER" />
</intent>
<!--For external application-->
<package android:name="com.whatsapp" />
</queries>
.....
.....
</manifest>
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