Deep-linking intent does not work

68

I followed the insttructions on https://developer.android.com/training/app-indexing/deep-linking.html, but when I want to trigger the intent through adb with:

adb shell am start
           -W -a android.intent.action.BROWSEABLE
           -d "http://example.com/gizmos" com.myapp.android

I just get

Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=example://gizmos flg=0x10000000 pkg=com.myapp.android }

<activity
        android:name=".activities.DeepLinkActivity"
        android:label="@string/title_activity_deep_link">
        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />

        <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="http"
                android:host="example.com"
                android:pathPrefix="/gizmos" />
        </intent-filter>
    </activity>

Have I made any obvious mistakes?

android
android-intent
android-manifest
deep-linking
asked on Stack Overflow Jul 17, 2014 by Mahoni • edited Jul 21, 2014 by Mahoni

12 Answers

125

EDIT:

Ok first make sure that your package is reachable by adb:

adb shell am start -n com.example.simon.test/.activities.MainActivity

Then to accept multiple data tags you need different intent filters (that's the way it worked for me unlike all the other examples I've seen on the net). E.g.:

<intent-filter>
    ...
    <data android:scheme="http"
          android:host="example.com"/>
</intent-filter>
<intent-filter>
    ...
    <data android:scheme="http"
          android:host="example.com"
          android:pathPrefix="/gizmos"/>
</intent-filter>

NOTE that in the above example the pathPrefix starts with a forward slash !

I am not sure why Google's Docs are so misleading or maybe that was for some different version of adb, but the above changes worked perfectly for me. This helped: Source


This is how I made the Chrome browser route specific links to my app:

<activity
    android:name=".activities.DeepLinkActivity"
    android:label="@string/app_name">
    <!-- Accept chrome links -->
    <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="http"
              android:host="example.com"
            android:pathPrefix="/"/>
    </intent-filter>
    <!-- Accept adb data flag -->
    <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="http"
              android:host="example.com"/>
    </intent-filter>
</activity>

NOTE The 1st filter works on Google Chrome while the 2nd one works on the ADB.

NOTE2 The app choice menu won't be shown if the link is entered into the browser's address bar. It has to be a <a href="http://example.com"></a> link in side some page.

In my opinion everything here is rather blurry and really not how I expected it all to work. But that's how it works on my device. Hope this helps (and works) for you too.

answered on Stack Overflow Jul 20, 2014 by Simas • edited Aug 23, 2014 by Simas
21

After some tests this is what worked for me:

    <activity android:name=".activities.MainActivity">
        <intent-filter android:label="@string/app_name">
            <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.example.com"
                  android:pathPrefix=""
                />
            <data android:scheme="myschema"
                  android:host="example"
                  android:pathPrefix=""
                />
        </intent-filter>
    </activity>

This works when clicking any link in the browser such as "http://www.example.com", "http://www.example.com/" or "http://www.example.com/whatever". The same with "myschema://example/whatever".

Also works with adb using this command (with any of those URLs):

adb shell am start -W -a android.intent.action.VIEW -d "http://www.example.com" com.example

Hope it helps to get you started.

When everything is working you will probably want to configure a different pathPrefix for different activities.

answered on Stack Overflow Sep 3, 2014 by Ferran Maylinch • edited Sep 4, 2014 by Ferran Maylinch
6

In my case, I was putting deep linking intent filter in MainActivity which is also main launcher. That caused the problem.

After I created another separate activity and put intent filter there, it solved the problem. Hope this can help others who are facing the same issue.

answered on Stack Overflow Sep 16, 2016 by Harry Aung
4

In my case, I am using an emulator and not an actual usb connected device, and hence I had to change -d to -e, like so :

adb shell am start -W -a android.intent.action.VIEW -e "http://www.example.com" com.example

Note the -e before the deep link.

answered on Stack Overflow Aug 25, 2020 by Prajval Prabhakar • edited Aug 25, 2020 by Prajval Prabhakar
3

First, read @user3249477's answer on this page.

I just wanted to add that instead of what he wrote, you can condense it by using pathPattern:

<activity
    android:name=".activities.DeepLinkActivity"
    android:label="@string/app_name">
    <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="http"
              android:host="example.com"
            android:pathPattern=".*"/>
    </intent-filter>
</activity>

The ".*" matches both the empty string and "/", so both cases are covered. If you end up trying to handle multiple scheme's and host's this becomes especially important, so you don't have to spam a powerset of {http, https} X {"", "/"} X {"foo", "bar", etc.}

answered on Stack Overflow Jan 22, 2015 by jdowdell
2

Make sure your URL is in this format (with the cap letters replaced by your own):

android-app://COM.YOUR.APP.IDENTIFIER/SCHEME/HOST?somegetparams

The adb tool does not require this format. With the above you can now put it in an src, or an href, like so:

<iframe src="android-app://COM.YOUR.APP.IDENTIFIER/SCHEME/HOST?somegetparams"> </iframe> 
<a href="android-app://COM.YOUR.APP.IDENTIFIER/SCHEME/HOST?somegetparams">LINK</a>
answered on Stack Overflow Oct 27, 2015 by Kelsey
2

In my case I have a port 8075 in the URL I removed it and it worked

answered on Stack Overflow Aug 8, 2017 by amorenew
2

./adb shell am start -n packagename/.splash.SplashActivity -d "schemeName://content"

answered on Stack Overflow Apr 16, 2018 by manmohan
1

Use adb shell am start -W -a android.intent.action.VIEW -d "http://example.com/gizmos" com.myapp.android

it will work.

answered on Stack Overflow Aug 3, 2017 by Shashikant
0

Thanks Simas for your response i would like to add some clarification:

  • after testing your activity with this command:

    adb shell am start -n com.example.simon.test/.activities.MainActivity

  • You will need to test your deeplinks ,after adding the intent filter to your AndroidManifest.xml file (lines are below):

    ... ...

so this is the adb command with which you can test :

adb shell am start -W -a android.intent.action.VIEW -d "http://example.com/gizmos" com.example.packageid

and

adb shell am start -W -a android.intent.action.VIEW -d "http://example.com" com.example.pakageid
-1

if you have not permission issue , it is probably related to API level

answered on Stack Overflow May 2, 2018 by Abolfazl Miadian
-2

Use this intent filter instead,

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

<!-- Accepts URIs that begin with "example://gizmos” -->
<data
   android:host="gizmos"
   android:scheme="example" />
</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" />

<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data 
    android:host="www.example.com"
    android:pathPrefix="gizmos"
    android:scheme="http" />
</intent-filter>
answered on Stack Overflow Mar 15, 2016 by alchemist

User contributions licensed under CC BY-SA 3.0