I am trying to test android deep link urls through adb to launch my app
Asked Answered
I

15

135

When I type the command in adb:

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

I get this error:

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

But when I type the command in adb:

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

Everything works fine and I get the message and I can see the activity launch on the phone:

Starting: Intent { act=android.intent.action.VIEW dat=example://gizmos cmp=com.myapp.activity.DeepLinkActivity }
Status: timeout
Activity: com.myapp.activity.DrawerActivity
Complete

My question is why do I need to get full path of my activity and not just package name? Because when the external apps or browser will try to deep link they will not invoke the activity in my app.

This is my AndroidManifest.xml

<activity
        android:name=".activity.DeepLinkActivity">
        <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="example"
                  android:host="gizmos" />

        </intent-filter>
</activity>
Iveson answered 2/3, 2015 at 3:7 Comment(0)
P
202

You don't need to specify full path to your activity, but if you want to test whether you react properly to URI in your app just specify app package:

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

Also there is bug in command you provided - there should be example://gizmos not example:gizmos

Plump answered 13/4, 2015 at 8:41 Comment(1)
While this works, when launch in Terminal of Android Studio it can write: /system/bin/sh: com.myapp: inaccessible or not found. The app link starts without error. To avoid this message, just remove com.myapp from the end.Deckle
M
133

Here is the command

adb shell am start -d your-deep-link

Example

adb shell am start -d rm://yoursettingpage/v1
Mikkel answered 7/11, 2019 at 5:24 Comment(6)
This is the best and simple answer for this question.Detritus
Completely agree: Best answer so farMarcimarcia
if you have extras in your deeplink (e.g. "?a=100&b=200") surround deeplink with "s and surround adb-shell with 's. example: adb shell 'am start -d "example://deeplink?a=100&b=200"'Antalya
this shows my app status as Ask, any solution? even i added autoVerify = trueAlena
Interesting, keep in mind that this won't add the categories BROWSABLE or action VIEW, Amaury answer is good too.Dessalines
What is the difference between declaring and omitting the -a android.intent.action.VIEW action argument?Roseboro
M
57

The best solution for android studio is explained here: https://code.tutsplus.com/tutorials/how-to-enable-deep-links-on-android--cms-26317

TLDR : Android Studio --> Run --> Edit Configurations

Change Launch in Launch Options to "URL" and enter in the text field URL the correct url: "something://"

Masters answered 24/3, 2017 at 9:50 Comment(1)
this is the best and easiest way, thanks!Fermentation
D
29

You can test your deeplink from Android Studio interface.

enter image description here

  1. Select Tools > App Links Assistant.
  2. Click Test App Links in the App Links Assistant.
  3. Enter the URL you want to test in the URL field, for example, http://recipe-app.com/recipe/grilled-potato-salad.
  4. Click Run Test.

Take a look for learn how to implement applinks via Android Studio Interface. https://developer.android.com/studio/write/app-link-indexing#testindent

Dreamworld answered 30/12, 2020 at 13:18 Comment(4)
This appears to only work for app links with an http or https schemeAstor
When I press run test, I get a success message but the page opens in my device's web browser.Accused
It works. First Gradle builds for a minute, then in emulator a dialog appears to choose between Chrome and an application. After selecting the application it opens a right screen. But it launches the application from the beginning (if it was opened before, it will be reopened).Deckle
@Accused You need to enable the link handling in the app-info screen too. I think it gets enabled automatically only when installed by the Play Store, or something. If you know this already, please share your insights of how it works.Osrick
N
16

As the other answer mentioned, it should be "example://gizmos" and not "example:gizmos"

Alternatively, instead of using adb, you can test deep links directly on android using deep link tester app:

https://play.google.com/store/apps/details?id=com.manoj.dlt

No need to mention any package name or component name. Just type the deep link and fire.

I've found testing deep links through adb to be cubersome and difficult at times. Hence, I've built this small app to do it.

Nepali answered 27/3, 2016 at 17:50 Comment(0)
U
16

The best way I found is through Android Studio itself.

  1. Open the Run/Debug Configurations dialog by selecting Edit Configurations... option like in the image below: open 'Run/Debug Configurations' dialog

  2. After that add a new configuration with options like in the below image (if you're using Firebase Dynamic Links then enter your dynamic link's short link in the URL field else enter your deep link instead in the URL field): Options in the 'Run/Debug Configurations' dialog

  3. After that, you'll find the run configuration, select it, and just press Run: enter image description here

Add as many run configurations for each link you want to test.

Uterus answered 23/3, 2021 at 13:15 Comment(2)
This should be the current answer, as the screenshot shows what to do.Sonyasoo
I suppose, it will start an application from the beginning. If we want to test an already opened app, it will start again.Deckle
T
13

Try this:

adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d 'yourdeeplink'

-a android.intent.action.VIEW -> action  -c android.intent.category.BROWSABLE -> category -d 'deeplink' -> data 

and also you need to install the app first in order to register the deeplink.

Turco answered 13/12, 2019 at 15:14 Comment(1)
-a android.intent.action.VIEW -> action ---------- -c android.intent.category.BROWSABLE -> category ---------- -d 'deeplink' -> data ---------- and also you need to install the app first in order to register the deeplink.Turco
M
9

Following should work

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

Here

example://gizmos

is the URI scheme that you have setup.

But if you want to pass additional parameters to URI scheme and test it,

example

example://gizmos?parameter1=23&parameter2=test

then the command would be,

adb shell 'am start -W -a android.intent.action.VIEW -d "example://gizmos?parameter1=23&parameter2=test"' com.myapp
Mudcat answered 18/5, 2022 at 11:22 Comment(0)
G
8

The command

adb shell dumpsys package domain-preferred-apps

is also very helpful to print all active deep link handlers known to the system. If your app is missing here, there's obviously something wrong with your deep link setup.

Godart answered 17/8, 2020 at 9:57 Comment(0)
R
8

If your deeplink has http or https scheme you can use the google text box in Android:

enter image description here

Just copy your deeplink there

Radiochemical answered 18/1, 2022 at 14:38 Comment(4)
It works! Работает!Deckle
It doesnt work for mine, maybe you already have your site already associated?Dessalines
@Dessalines Try to check your application settings in android and look at "Open by default" Maybe you have to add your link thereRadiochemical
does not work, but when type text on programs like slack on real device it navigate correctlyOverweary
V
7

Your command is incorrect because you are trying with an incorrect package name, Instead of com.myapp.activity.DeepLinkActivity you have to write only the package name specified in build gradle(Module: app) by 'application Id' e.g if your applicationId is com.companyname, then your command would be like this:

adb shell am start -W -a android.intent.action.VIEW -d  "example://gizmos" com.companyname
Vaasa answered 16/8, 2016 at 11:59 Comment(0)
D
3

Just in case someone else has the problem that I had, namely that adb shell am start ... does not work, if you have a file:///... or content://...URI in your intent filter that has a mime type specified, for example

<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="content" />
  <data android:scheme="file" />
  <data android:mimeType="text/plain" />
  <data android:host="*" />
</intent-filter>

You need to specify the mime type on the command line by using the -t parameter:

adb shell am start -W -a android.intent.action.VIEW -d "file:///sdcard/myfolder/myfile.txt" -t "text/plain" com.myapp

or else you get the same error message as the OP.

Based on the experience I just had I recommend using this list of available adb commands. It seems to be more recent than the help texts from the shell of my test device running Android 8.

Dulla answered 11/4, 2019 at 21:18 Comment(0)
B
2

Testing deep-linking by running adb shell command seems troublesome to me. So I tried an Easy Solution to reduce my task and time to test deep-linking multiple time using .bat file.

Step 1: First create a .txt file and paste here your ADB command -

adb shell am start -W -an android.intent.action.VIEW -d <Your URL> <Your Package>

and save the file changing .txt extension into .bat. Now you have just created your bat file to test deeplink. Try to use just one letter to name the bat file (Like I named d.bat , "d" for "deeplinking" for easy understanding) because it reduce your time of typing.

Step 2: Now open your terminal in Android studio and go to your bat file location and just type your file name (without extension) and press enter. For example cd your/bat/file/location/d here suppose "d" is your bat file name.

It will work spiffy!

Benitabenites answered 22/8, 2020 at 6:37 Comment(1)
missing "-c android.intent.category.BROWSABLE"Cragsman
D
2

Search Google Play for DeepLink. Download apk (via other sites that support downloading). Then install the application on emulator. For instance, https://play.google.com/store/apps/details?id=com.waterbottle.testdeeplink.

enter image description here

Deckle answered 22/3, 2022 at 9:17 Comment(0)
V
1

I found Savas Adar's answer the most friendly to use, also makes much more sense to have an inbuilt tool for that purpose.

Just use that!

I have three quick disclaimers about the App Links Assistant which are missing in his answer and a comment was too long.

  1. Open App Links Assistant. I couldn't find it in the Tools menu. So double press Shift and type App Link Assistant to run it from Android Studio

  2. Pressing "Run Test" would clear the edit text box so I found myself having to copy and paste my link every time I wanted to re-try the test. Foolish of myself not reading the text literally above it saying that after running a test a Run Configuration gets created with the previous url attached to it. (Top of the screen, left of the device menu). Just select the run configuration with the url you want.

  3. I found that pressing "Run Test" would restart the app unlike the ABD approach which is no biggie (just slower) until I wanted to debug. I ran the app in the debug mode and then pressed Run Test which would stop my debugging sessions and restart the app...

Solution is to choose the Run Configuration from point 2, and just run it as a debug.

Visakhapatnam answered 5/1, 2021 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.