Open android-app scheme with Chrome on Android
Asked Answered
O

1

6

I was wondering how I'd have to configure my app to open it with android-app://application.id?

adb shell am start android-app://application.id

The URI_ANDROID_APP_SCHEME seems not to work as documented. Instead Chrome and Firefox only open a market:// link to my app.

For Chrome I found a documentation only describing the intent:// scheme.

When the intent filter contains the DEFAULT and BROWSABLE category it works with Firefox.

<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Opossum answered 18/2, 2020 at 9:21 Comment(0)
H
3

You have to add <data../> describing URI in intent-filter for your component, like so,

<intent-filter>
   ...

   <data android:scheme="android-app"/>
</intent-filter>

and on your site part define intent like this

intent:#Intent;scheme=android-app;package=your_package;end

UPDATE. Didn't realize that scheme was a reserved one, although my solution works for any scheme you define. I looked up the sources of the Intent class it seems you have to define your URI like this

android-app://your_package

OR

android-app://your_package/ 
#Intent;action=com.example.MY_ACTION;end

First line of the parseUri method in the Androids Intent class

final boolean androidApp = uri.startsWith("android-app:");

Worth to mention: This scheme was added on API 22.

I've tested it works with a tag, and as @tynn mentioned in the comments also for window.open() and location.href and not working from the address bar in Chrome.

Henequen answered 25/2, 2020 at 12:7 Comment(7)
The android-app scheme is one handled from within the system. Not one you'd declare yourself. Have a look at the adb command I posted. That's working for me.Opossum
I looked up further, please check my updated answer. Hope this helpsHenequen
My intention is to open this automatically. Actually I made it work somehow from Firefox. When I type android-app://application.id in the address bar and open it, it will open the app or the market if the app is not installed. Sadly Chrome just opens the search and Chrome is my main use-case. I'll update the question later with my findings. Thanks for your efforts so far!Opossum
I was testing with <a href="android-app://app.id">.. on Chrome, it worked for me.Henequen
So basically it works from a link, but not from the address bar. That's really confusing. Thanks!Opossum
It seems to work with a and window.open() and location.href. Could you add this point to your answer. Then I'll just accept it.Opossum
great, helpful.Edris

© 2022 - 2024 — McMap. All rights reserved.