首页 文章

深层链接意图不起作用

提问于
浏览
45

我按照https://developer.android.com/training/app-indexing/deep-linking.html上的说明进行操作,但是当我想通过 adb 触发意图时:

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

我得到了

错误:活动未启动,无法解析Intent

<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>

我有任何明显的错误吗?

11 回答

  • 11

    EDIT:

    好的,首先确保adb可以访问您的包:

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

    然后要接受多个数据标签,您需要不同的意图过滤器(在网上看到的).1405955_ . 例如 . :

    <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 在上面的例子中,pathPrefix以正斜杠开头!

    我不确定为什么Google的文档会如此误导,或者可能是因为某些不同版本的adb,但上述更改对我来说非常合适 . 这有助于:Source


    这就是我将Chrome浏览器路由指向我的应用的特定链接:

    <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 第一个过滤器适用于Google Chrome,第二个适用于ADB .

    NOTE2 应用程序选择菜单赢得了't be shown if the link is entered into the browser'的地址栏 . 它 has 是一些页面中的 <a href="http://example.com"></a> 链接 .

    在我看来,这里的一切都相当模糊,而且我的预期并非如此 . 但这就是它在我的设备上的工作方式 . 希望这对你有帮助(也有效) .

  • 1

    经过一些测试后,这对我有用:

    <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>
    

    单击浏览器中的任何链接(例如“http://www.example.com ", " http://www.example.com/ " or " http://www.example.com/whatever ". The same with " myschema:// example / whatever”)时,此方法有效 .

    也可以使用此命令(包含任何这些URL)与 adb 一起使用:

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

    希望有助于您入门 .

    当一切正常时,您可能希望为不同的活动配置不同的 pathPrefix .

  • 1

    就我而言,我在MainActivity中加入了深层链接意图过滤器,MainActivity也是主要的启动器 . 这导致了这个问题 .

    在我创建另一个单独的活动并将intent过滤器放在那里之后,它解决了问题 . 希望这可以帮助那些面临同样问题的人 .

  • 1

    首先,在此页面上阅读@ user3249477的答案 .

    我只想添加而不是他写的内容,你可以使用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>
    

    “ . *”匹配空字符串和“/”,因此两种情况都被覆盖 . 如果你最终试图处理多个方案和主机,这变得尤为重要,所以你不必垃圾邮件{http,https} X {“”,“/”} X {“foo”,“bar”等等}

  • 1

    确保您的网址采用此格式(封顶字母替换为您自己的):

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

    adb工具不需要此格式 . 有了上面的内容,您现在可以将它放在src或href中,如下所示:

    <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>
    
  • 87

    使用adb shell am start -W -a android.intent.action.VIEW -d“http://example.com/gizmos”com.myapp.android

    它会工作 .

  • 0

    在我的情况下,我在URL中有一个端口8075我删除它并且它工作

  • 2

    请改用此意图过滤器,

    <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

    感谢Simas的回复,我想补充一些说明:

    使用此命令测试活动后

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

    • 将意图过滤器添加到AndroidManifest.xml文件后,您需要测试深层链接(如下所示):

    ......

    所以这是你可以测试的adb命令:

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

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

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

  • 0

    如果您没有权限问题,则可能与API级别有关

相关问题