android – How to open app from a link without asking user to decide between browser or app, just open my app immediately-ThrowExceptions

Exception or error:

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?

How to solve:

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.

###

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 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 log 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.

###

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

###

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

###

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

###

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

Leave a Reply

Your email address will not be published. Required fields are marked *