Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open android-app scheme with Chrome on Android

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>
like image 872
tynn Avatar asked Feb 18 '20 09:02

tynn


People also ask

Can I open the app from browser Android?

Opening an installed app from a browser is known as “deep linking”, and with this guide you'll learn how to deep link into your Android app from the mobile web. We'll focus exclusively on how to trigger an app open from a website page, rather than from the click of a link inside other apps.


1 Answers

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.

like image 199
Tiko Avatar answered Sep 29 '22 14:09

Tiko