Targeting AndroidSdk 30, webIntent.ACTION_VIEW is broken on Android phone With Android 11
Closed this issue · 8 comments
Hello,
My version of this plugin is 2.0.0
cordova-android 9.0.0
cordova cli 10.0.0
I'm building an ionic5 app, and have a problem on Android when targetting AndroidSdk 30 (For Android 11 needed by November 2021 : https://developer.android.com/distribute/play-policies#APILevel30 )
I try to open another app with extra from an Deeplink URL using WebIntent like this :
const options: IntentOptions = {
action: this.webIntent.ACTION_VIEW,
url: https://url-for-deeplink,
extras: {
returnBundle: {returnJson: "somthing"},
},
};
this.webIntent.startActivity(options).then(() => {
// deeplink is opened ko
}, () => {
// Error during opening deeplink
});
On an Android 11 phone, it works well when i'm targetting AndroidSdk 29 using cordova-android@9.0.0
But, By November 2021, we must target AndroidSdk 30, and adding in my config.xml this :
<preference name="android-targetSdkVersion" value="30" />
The startActivity doesn't work, there is an error wich say : Error
I think it is because of the permission QUERY_ALL_PACKAGES :
https://support.google.com/googleplay/android-developer/answer/10158779?hl=en
I can't use other cordova plugin to open other app just with package name for exemple, because i need to send in param of this app json (what i did in the exemple with "extras")
It is just broken on Android phone 11 (below is ok) when targetting sdk30
I can't add the QUERY_ALL_PACKAGES permission to my app becase my app is not sensible as explain here by google : https://support.google.com/googleplay/android-developer/answer/10158779?hl=en#
Is there a way to fix this ?
Thanks for help
Hi, is QUERY_ALL_PACKAGES
a permission you are adding? I don't see that this plugin requests it. If so, please see https://developer.android.com/training/package-visibility for the workarounds for A11 package visibility changes.
If i add QUERY_ALL_PACKAGES permission, then it works on A11 phones when my app targetting AndroidSdk 30.
But if i add this permission, my app will be strike by google, because it is not a legitime permission.
I only need to see the app i want to open, and not all the apps.
It is explain there : https://support.google.com/googleplay/android-developer/answer/10158779?hl=en#zippy=%2Cpermitted-uses-of-the-query-all-packages-permission
Wouldn't you use the queries element in that case? https://developer.android.com/guide/topics/manifest/queries-element
Thanks for your help
I have not allready try "queries" , so i will test it
It's not my first priority but i will write results of my tests in many days / week !
I didn't think someone could help me as fast !
Hello, i can confirm that adding with package of the app i intent, in AndroidManifest.xml is solving my bug
It is sad, because i used a deeplink before, and didn't need to know the package of the app. Now, yes.
I'm looking for how to add it in a proper way, from config.xml with edit-config for exemple, but, there is still another bug with this : apache/cordova-android#1245
Moreover, if the app is not installed, my intent using deeplink return ko. So i need to check before if the app is installed, with cordova-plugin-appavailability, and if yes, processing my intent, if no, just open with inappbrowser my deeplink url
To conclude, queries was necessary like you said darryncampbell
Moreover, if the app is not installed, my intent using deeplink return ko. So i need to check before if the app is installed, with cordova-plugin-appavailability, and if yes, processing my intent, if no, just open with inappbrowser my deeplink url
Not sure if this is completely relevant to you but I remember reading about FLAG_ACTIVITY_REQUIRE_NON_BROWSER from https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9, sounds like it could be useful here?
Well, the only error i have from the native interface of ionic is the string "error" :
this.webIntent.startActivity(options).then(() => {
// deeplink is opened ok
}, (error) => {
console.log(error) // => error is not an object, juste the string "error"
});
I don't think, the native error code is propagate, older nor newer
The check of the app installed works, i'll continue with this for the moment
Thanks again
So the final solution is to add queries via config-file in config.xml like this :
<config-file target="AndroidManifest.xml" parent="/manifest" xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<package android:name="my.package.name1"/>
<package android:name="my.package.name2"/>
</queries>
</config-file>