How to open app from a link without asking user to decide between browser or app, just open my app immediately
Asked Answered
E

7

29

I have this intent-filter that I want that every time user clicks a link to eeexample.com to open my app:

<intent-filter>
    <data android:scheme="http" />
    <data android:scheme="http" android:host="eeexample.com"/>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

When user clicks eeexample.com on gmail app for example: enter image description here

Which then opens a dialog which asks user if they want this link to be opened from my app or browser like this:

enter image description here

But I just want that when user clicks the link it opens ONLY my app without asking anything. Or in a worst case scenario to just ask to open it with my app which is Appetit not with browser. Is this possible?

Update

So it seems this is possible to do with App Links but only for API level 23 (Android 6.0), but I need this for api level 15 (Android 4.0), any ideas?

Exoteric answered 18/12, 2015 at 16:18 Comment(0)
L
19

Bypassing the disambiguation dialog is only possible with the Android 6.0 API for App Linking.

Per the Handling App Links training:

Android 6.0 (API level 23) and higher allow an app to designate itself as the default handler of a given type of link. If the user doesn't want the app to be the default handler, they can override this behavior from Settings.

Automatic handling of links requires the cooperation of app developers and website owners. A developer must configure their app to declare associations with one or more websites, and to request that the system verify those associations. A website owner must, in turn, provide that verification by publishing a Digital Asset Links file.

This involves creating the appropriate intent handler and enabling automatic verification by adding android:autoVerify="true":

<activity ...>

  <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="www.android.com" />
    <data android:scheme="https" android:host="www.android.com" />
  </intent-filter>

</activity>

Then, updates must be made on the website side by declaring a website association, which ensures that the website owner and the app developer both coordinate to allow the app to autoomatically become the default for a URL scheme.

Leslileslie answered 18/12, 2015 at 16:55 Comment(4)
Prior to 6.0, the user will always see a disambiguation from apps such as Gmail. There is App Indexing for deep linking to your app from Google Search which works back to API 17.Leslileslie
I am trying to do this, my server is a http server. Its not working. is it mandatory to be https server for deep-linking permission?Elis
@AshikurRahman - per this link, Digital Asset Links do indeed require HTTPS on your server. As they say on that link, you can associate your app with a website on the Search Console if you need to support HTTP.Leslileslie
hey @Leslileslie I have digital assets set on the server. I am doing authentication through a customtabintent server re-directs to my deeplink but the system ( on some versions of chrome) doesn't catch the url and it loads it on the browser instead. Is this expected? (don't see this on samsung browsers)Cyndycynera
N
9

Here are a couple of places you can use to verify that .well-known/assetlinks.json is accessible, which is an important prerequisite for removing the disambiguation dialog.

https://developers.google.com/digital-asset-links/tools/generator

https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://YOUR_WEBSITE&relation=delegate_permission/common.handle_all_urls

As for my case, despite everything checks, the disambiguation dialog just wouldn't go away. It turned out that I was also using FirebaseUI Auth for GitHub (https://github.com/firebase/FirebaseUI-Android/tree/master/auth), which uses firebase_web_host; if it's defined as something other than the value defined in android:host, then android:autoVerify also fails as well.

The problem was, firebase_web_host was buried somewhere outside of my code, so it wasn't exactly obvious why android:autoVerify was failing. One easy way to find out is to check adb logcat when installing the app; you should see something like

IntentFilterIntentSvc: Verification .. complete. Success:true. Failed hosts:.

If you see Success:false, it should show which hosts failed, so that should give you a clue on where to look.

Noisome answered 25/7, 2018 at 23:52 Comment(4)
In my case it fails, since the SHA256 key used for debug variant doesn't match with the hosted one.Rolanda
awesome answer , but how can I authenticate file /.well-known/assetlinks.json to be not shown in server and keep working with android os ?Gondolier
Not sure you can hide ".well-known/assetlinks.json" AND bypass the disambiguation dialog at the same time. "assetlinks.json" contains app package name and SHA256, which aren't considered as security concern.Noisome
this helped a lot. by the way IntentFilterIntentSvc is now IntentFilterIntentOpHarper
A
3

all you have done is correct just change https and http with another word wirte 'app' example data android:scheme="app" android:host="com" android:pathPrefix="/easy"

http or https means run browser then cause conflict

Aniseikonia answered 28/8, 2018 at 8:23 Comment(0)
T
3

in your AndroidManife.xml put

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

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

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

for example

 <activity
        android:name="Activity"
        android:exported="true"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

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

after that when click on any url with scheme "myAPP" Your application will open No user requests

for example URL

myAPP://yoursite.com

myAPP://any.site.com

Tact answered 16/1, 2019 at 7:45 Comment(0)
A
0

I have searched a lot for an accurate answer, but it is incredibly frustrating that not even in the documentation of Android we can not get a good and straight answer. I tried a lot, differents structures for the URL for opening the app, at the end, the documentation part for what to put in the manifest is correct, you only need to set an intent, with host and a scheme, like following:

<activity ...>

  <intent-filter>
            <data android:scheme="schemeName" android:host="hostName" android:path="/"/>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
        </intent-filter>

</activity>

Where in schemeName and hostName can be anything you want, the important part is not in the documentation, is how to successfully call the app in a link, so for doing that you must create a link following this structure:

intent://hostName/#Intent;scheme=schemeName;package=your.app.package;end

Where in your.app.package goes your app package. Remember you can get your app package from the manifest. I really hope to help a lot of people, i searched a lot but most important tested a lot to get the correct URL structure to open the app.

Anam answered 27/5, 2021 at 11:17 Comment(0)
S
-1

So here is one way to do it, but as far as my experience I am not completely 100% sure that it always works: since if some other app also uses the same mechanism of setting priority then it might be shown in the list of suggested app by Android OS

when you declare an intent filter to respond to the events you can also set the priority something like

<intent-filter android:icon="drawable resource"
   android:label="string resource"
   android:priority="integer" >
 // some other properties
 </intent-filter>

the priority provides information about how able an activity is to respond to an intent that matches the filter, relative to other activities that could also respond to the intent. When an intent could be handled by multiple activities with different priorities.

note that Android will consider only those with higher priority values as potential targets for the intent.

so what should be the value of priority? The value must be an integer, such as "100". Higher numbers have a higher priority. The default value is 0. The value must be greater than -1000 and less than 1000.

the -1000 is SYSTEM_LOW_PRIORITY and the 1000 is SYSTEM_HIGH_PRIORITY

here are some of the android docs link that might help you know more-

intent-filter

more about setting priority

hope this helps! all the best

update note that whatever you do, for the first time you have to go through the step where user selects to open the app

Selfassurance answered 18/12, 2015 at 16:41 Comment(0)
R
-5

In android you can not force link to open from specific app without user confirmation.

Once user click on Always from next time, your app will be open

Regal answered 18/12, 2015 at 16:35 Comment(4)
ok is it possible to dialog that prompts to just ask to open it from my app (Appetit) without displaying browser as another option?Exoteric
No, it will show all the apps which mention that link as intent-filter option. and in android browser is there so, it will show.Regal
It is possible in Android by Using Applink AutoVerification developer.android.com/training/app-links/…Felic
Android 6.0 and above supports this feature. you can refer these links developer.android.com/studio/write/app-link-indexing.html and developer.android.com/training/app-linksQuart

© 2022 - 2024 — McMap. All rights reserved.