Support intent: and android-app: url schemes in templates#4229
Support intent: and android-app: url schemes in templates#4229timrae merged 2 commits intoankidroid:developfrom
Conversation
1b3ea15 to
66c1fa0
Compare
|
Tested against pre-22 (as well as 22+). It is safe to use |
|
Is there any documentation on that android-app scheme? It'd be nice if there was a cleaner way which was better documented. The docs seem to just recommend using a custom scheme. |
|
The only documentation is here unfortunately. Definitely the Android team pushes devs away from custom schemes. It looks like Chrome supports custom schemes (less and less) rather than encourages them. That link you included shows the dev how to use an This PR is working really well for me and tested on various API levels. Once AnkiDroid supports |
Ooops, sorry I was skim reading. Have you tried using the fallback URL mechanism mentioned in the docs I linked you to?
If you give it the URL to your google play listing, it should automatically get redirected to the play app on almost all versions of Android I think. |
That works if I click on the link within Google Chrome, but not if the link is in the template. No idea why that should be the case. When AnkiDroid finds that the resolved intent is not available, it should probably call the fallback URL (if one is set), otherwise use the market:// How does that sound? |
|
Looks like it's already discussed here. |
66c1fa0 to
4da8016
Compare
|
I've just added support for |
|
Did you see the comment about adding BROWSABLE? As I'm sure you know, since Kitkat the Webview is using Chromium so it's supposed to behave the same as Chrome. |
My angle was more to let the Android system deal with the intent in a standard way rather than adding lots of rules to AnkiDroid. |
Yeah I agree AnkiDroid shouldn't be doing this unless it has to (as a workaround). Nice spot regarding the BROWSABLE category. I'll try it out now. Although IMO, it seems a little silly to insist that the intent uri MUST include that category (why else would a template include the intent uri?). Also worth noting that my intent-filter always had both the DEFAULT and BROWSABLE categories included. |
|
BTW, I also tried disabling the custom WebViewClient (by not setting it), to see if the webview would handle the intent uri differently. However, that also does not work. EDIT: this is true only regarding the fallback url. |
|
Oh, actually if you don't set the WebViewClient then the intent: uri is automatically resolved and used. However, it looks like the fallback url is not resolved (Web page note available). I tried this using the zxing examples given in that Chrome link. Note that those intent uris do not include the BROWSABLE category. So regardless, it looks like we need to resolve these links manually. |
|
I tried adding the BROWSABLE category to the intent uri and that doesn't seem to make any difference compared to not adding it. This is true for when setting the WebViewClient and also when not setting it. Also worth noting that my intent-filter always had both the DEFAULT and BROWSABLE categories included. |
fa9b606 to
375a6ae
Compare
|
Made small change - remove fallback url from resolved intent (as mentioned here: https://developer.chrome.com/multidevice/android/intents) |
375a6ae to
427b542
Compare
427b542 to
e3de2d1
Compare
| } | ||
| } else { | ||
| // https://developer.chrome.com/multidevice/android/intents says that we should remove this | ||
| intent.removeExtra(EXTRA_BROWSER_FALLBACK_URL); |
There was a problem hiding this comment.
Should we add the Intent.CATEGORY_BROWSABLE here?
|
Can you please remove all the fallback URL stuff? I only suggested adding it as a way to remove the explicit market redirect; if that doesn't work then I prefer to ignore that attribute entirely. |
| if (url.startsWith("intent:")) { | ||
| intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); | ||
| } else if (url.startsWith("android-app:")) { | ||
| intent = Intent.parseUri(url, Intent.URI_ANDROID_APP_SCHEME); // note - also works pre-22 |
There was a problem hiding this comment.
Why would this work pre-22? Even if it somehow did work in your tests, the doc says added in 22 so I don't want to use it in production code.
There was a problem hiding this comment.
Presumably the constant is inlined at compile time and then parseUri is able to deal with the flag, at least to some extent. Shall I just add a Build.VERSION.SDK_INT if statement?
There was a problem hiding this comment.
Weird... Yeah maybe just squeeze it in with url.startsWith("android-app:")
There was a problem hiding this comment.
I think we should still parse it, otherwise templates will behave differently on different devices. You can see from the format there is very little difference between intent: and android-app: uris...
There was a problem hiding this comment.
Tbh I don't see much point in including support for android-app:
There was a problem hiding this comment.
I.e. I think we should just pass those URIs through.
There was a problem hiding this comment.
For consistency, it makes sense to treat intent: and android-app: the same. Just like Chrome does.
|
I've removed the fallback url stuff and improved the android-app: support (including testing on API16). |
| } | ||
| } else { | ||
| // https://developer.chrome.com/multidevice/android/intents says that we should remove this | ||
| intent.addCategory(Intent.CATEGORY_BROWSABLE); |
|
Thanks! |
Following on from this discussion.