Trying to enable deep linking to android app, testing intent can't launch activity
Asked Answered
N

5

11

I'm trying to enable deep linking so that certain links launch my app.

I read this turotial https://developer.android.com/training/app-indexing/deep-linking.html and following it pretty close but when I try to test it by using adb to send the VIEW intent to the app I just get the error

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

DeepLinkActivity.java

public class DeepLinkActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getAction() == Intent.ACTION_VIEW) {
        Uri uri = getIntent().getData();

    }

  }
}

Android Manifest declaring deeplink activity

<activity android:name="com.myapp.DeepLinkActivity" >
        <intent-filter>

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

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


            <data
                android:host="gizmos"
                android:scheme="example" />
            <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
            <data
                android:host="www.example.com"
                android:pathPrefix="gizmos"
                android:scheme="http" />
        </intent-filter>
    </activity>

ADB command to send the view intent

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

But I don't think I even need the full path to the activity

adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp
Nameless answered 8/9, 2014 at 22:10 Comment(1)
@Nameless Hi Brain, I'm doing the same thing and getting same result, can you tell me what you did to solve it.Aeolic
G
3

In your manifest you defined your scheme as "http" but in your intent constructor you are using "example."

Gloss answered 8/9, 2014 at 22:47 Comment(5)
Hi soundsofpolaris, I'm doing the same thing and getting same result as @Brain, can you tell me whats the problem now.Aeolic
Hi, did u solve this issue. If yes could you please share the code.Chemistry
@Chemistry according to the manifest, it should be: example.com, which is putting the "scheme" and the "host" together. But in his shell code it says example://gizmo. If you wanted that, the manifest should have "example" as the scheme, and "gizmo" as the host.Gloss
Have anyone solved it ? I have same problem. But not able to solveLaux
I have the same problemLaux
P
31

Try skipping package param entirely. I had exactly same problem and it works.

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

Pilpul answered 15/6, 2016 at 15:45 Comment(3)
I just reproduced this fix - skipping the package triggered the deep link. Unfortunately, currently intent.getData() is returning null, which it shouldn't.Kin
Thanks, the error disappeared. In emulator it opens Google Chrome with the link, if android:pathPrefix=".*", and a dialog to choose Chrome or my app, if android:pathPrefix="/something".Urbai
@SomeoneSomewhere, in my case it returns part of a request after /, as expected.Urbai
L
4

Comment out the second data part from your Android Manifest. As per google documentation of deep link :

"Intent filters may only contain a single data element for a URI pattern. Create separate intent filters to capture additional URI patterns."

Lavone answered 21/12, 2015 at 10:35 Comment(0)
R
4

Simply try as follows

Command:
adb shell am start -d your-deep-link

Example:
adb shell am start -d rmagazine://opensetting/v1
Replevy answered 6/12, 2019 at 5:3 Comment(0)
G
3

In your manifest you defined your scheme as "http" but in your intent constructor you are using "example."

Gloss answered 8/9, 2014 at 22:47 Comment(5)
Hi soundsofpolaris, I'm doing the same thing and getting same result as @Brain, can you tell me whats the problem now.Aeolic
Hi, did u solve this issue. If yes could you please share the code.Chemistry
@Chemistry according to the manifest, it should be: example.com, which is putting the "scheme" and the "host" together. But in his shell code it says example://gizmo. If you wanted that, the manifest should have "example" as the scheme, and "gizmo" as the host.Gloss
Have anyone solved it ? I have same problem. But not able to solveLaux
I have the same problemLaux
M
3

The problem is you have one intent filter for 2 types of deep links:

<activity
    android:name="app.myActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait">
    <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" />
        <data
            android:host="www.example.com"
            android:pathPrefix="/gizmos"
            android:scheme="http" />
        <!-- note that the leading "/" is required for pathPrefix-->                
    </intent-filter>
</activity>

And you will be able to use both on the ADB shell. Please see my full answer here

Mayonnaise answered 24/12, 2015 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.