Deep-linking intent does not work

前端 未结 12 1064
旧时难觅i
旧时难觅i 2020-12-07 14:29

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:

相关标签:
12条回答
  • 2020-12-07 15:08

    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>
    
    0 讨论(0)
  • 2020-12-07 15:12

    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>
    
    0 讨论(0)
  • 2020-12-07 15:14

    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.

    0 讨论(0)
  • 2020-12-07 15:16

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

    0 讨论(0)
  • 2020-12-07 15:18

    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.

    0 讨论(0)
  • 2020-12-07 15:19

    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.

    0 讨论(0)
提交回复
热议问题