Android deep linking works in ADB, but not browser
Asked Answered
F

3

11

I am trying to add deep linking to my app. I have added 2 intent filters to one of my activities, one filter for the "http" scheme, and another for my custom scheme (I'm using "example"). I have added one intent filter per scheme, based on the info in this SO (Deep-linking intent does not work), so that I can handle both example://test and http://www.example.com/test type of links.

Here is my XML:

        <activity
    android:name="com.myapp.myapp.SplashActivity"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter android:label="Intent Filter label">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.LAUNCHER" />
        <!-- Accepts URIs that begin with "http://www.example.com/test2” -->
        <data android:scheme="http"
              android:host="www.example.com"
              android:pathPrefix="/test2" />

    </intent-filter>
    <intent-filter android:label="Intent Filter label">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.LAUNCHER" />

        <!-- Accepts URIs that begin with "example://test2” -->
        <data android:scheme="example"
              android:host="test2" />
    </intent-filter>
</activity>

They are loading correctly when I test in ADB:

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

returns

Starting: Intent { act=android.intent.action.MAIN dat=example://test2 pkg=com.myapp.myapp }
Status: ok
Activity: com.myapp.myapp/com.app.myapp.SplashActivity
ThisTime: 357
TotalTime: 357
Complete

However, I get absolutely nothing in a browser. When I try this in a browser: "example://test2" in FF I get "couldn't find an app to open this link" and in Chrome and the Native Browser, it opens up new Google search for "example://test2".

When I try the other style: "http://www.example.com/test2" it just tries to navigate to that web page in all 3 browsers.

I am deploying the app to my phone from Android Studio. I have also tried by generating a debug APK, sending it to my phone, and installing. Same result for both. What am I doing wrong? I've followed the guide (https://developer.android.com/training/app-indexing/deep-linking.html) to the letter as far as I can tell. Does my app need to be in the store for the deep linking to work?

Floruit answered 17/11, 2015 at 23:18 Comment(1)
Thanks for asking this. I am having a similar issue and tho this answer was not my problem it did answer my questions about how to setup deep linking in android.Gayn
F
7

Ughh, my action was MAIN when it should have been VIEW...

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

...

<intent-filter>
        <action android:name="android.intent.action.VIEW" />
Floruit answered 18/11, 2015 at 20:6 Comment(1)
new to android can you provide detail on which line of XML you made changes, and it works facing the same issueCreamer
T
1

Your implementation seems to be correct and also, if you're testing your app in your device, it does not need to be available on Playstore.

Have you tried testing through a QR code? As is demonstrated in Google documents - https://developers.google.com/app-indexing/android/test

Hope this helps.

Thermal answered 20/11, 2015 at 12:28 Comment(0)
I
1

The scheme (and probably host) have to be in all lower case.

From the uni_link package i copied the deep link 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 YOUR_SCHEME://YOUR_HOST -->
      <data
        <!-- THIS HAS TO BE IN ALL LOWER CASE -->
        android:scheme="[YOUR_SCHEME]"
        <!-- android:scheme="[your_scheme]" -->
        android:host="[YOUR_HOST]" />
</intent-filter>

and pasted in my package name com.myPackage.app as the scheme. For the host I put localhost. Changing the scheme to all lower case com.mypackage.app allowed the deep link to work.

You can use this site to test the deep link without using adb.

PS: This is not true for iOS where the CFBundleURLName and CFBundleURLSchemes can contain uppercase letters.

Inartificial answered 24/1, 2022 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.