Fallback URL (or other behaviour) for links where URI not supported

1,818 views
Skip to first unread message

Mark Carter

unread,
Apr 20, 2016, 1:24:53 AM4/20/16
to AnkiDroid
In my template I have links like `<a href="myappscheme:path/to/uri">Click Me</a>`. However these links will obviously not work if my app is not installed. Is there a way to take the user to the app install page on Google Play, for example?

Flavio Lerda

unread,
Apr 20, 2016, 5:58:24 AM4/20/16
to AnkiDroid
Hello,

As far as I know, there is no way to specify a fallback for a URI.

I would suggest trying out using either:
or:
instead of a custom scheme.

These should be guarantee to open your app and not another app, and should open the Google Play Store if the app is not installed.
I have not checked in a while, so cannot speak in details to the exact behavior, but should help in your case.

Hope this helps,
Flavio

On Wed, 20 Apr 2016 at 06:24 Mark Carter <ma...@marcardar.com> wrote:
In my template I have links like `<a href="myappscheme:path/to/uri">Click Me</a>`. However these links will obviously not work if my app is not installed. Is there a way to take the user to the app install page on Google Play, for example?

--
You received this message because you are subscribed to the Google Groups "AnkiDroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anki-android...@googlegroups.com.
To post to this group, send email to anki-a...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/anki-android/8fb65d86-e980-42cd-bf7d-841a55dc01d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Carter

unread,
Apr 23, 2016, 11:01:24 AM4/23/16
to AnkiDroid
Thanks Flavio, that's really useful. I'd totally forgotten about Dianne Hackborn reminding devs (6 years ago) not to use custom schemes!

I've tested out both the intent: and android-app: schemes and they work-ish (but I don't think as intended).

AnkiDroid (I'm using the version on Play Store) kicks off an "android.intent.action.VIEW" intent with the "intent:" or "android-app:" uri as the data.  I was expecting AnkiDroid to resolve it using Intent.parseUri() and then start an activity using that.

So, to get this working, I needed to add the following to my intent-filter (this feels wrong):

<action android:name="android.intent.action.VIEW" />
<data android:scheme="intent"/> or <data android:scheme="android-app" android:host="com.mycompany.myapp"/>

The "intent:" one is particularly bad because that would catch all "intent:" uris.  The fact that no other apps on my device support this "intent:" uri (no Intent chooser comes up) suggests that AnkiDroid is not handing the intent uri properly. The "android-app:" scheme is handled by the Google App which presumably is responsible for choosing whether forward the uri to the app or Play Store app.  Curiously if I let Google App handle the uri then the Play Store opens but with a blank screen.

Any pointers as to which part of the AnkiDroid code handles such intents, so I can take a look?

Mark Carter

unread,
Apr 23, 2016, 11:50:51 AM4/23/16
to AnkiDroid
I found the relevant code in AnkiDroid, and made a new PR.
Reply all
Reply to author
Forward
0 new messages