深联的意图不工作 [英] Deep-linking intent does not work

查看:179
本文介绍了深联的意图不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也跟着在<一的insttructions href="https://developer.android.com/training/app-indexing/deep-linking.html">https://developer.android.com/training/app-indexing/deep-linking.html,但是当我想通过触发的意图亚行

  ADB壳分开始
           -W -a android.intent.action.BROWSEABLE
           -dhttp://example.com/gizmoscom.myapp.android
 

我刚刚得到

  

错误:活动还没开始,无法解决意向{   ACT = android.intent.action.VIEW DAT =例如://小玩意FLG = 0x10000000处   PKG = com.myapp.android}

 &LT;活动
        机器人:名称=。activities.DeepLinkActivity
        机器人:标签=@字符串/ title_activity_deep_link&GT;
        &所述;元数据
            机器人:名称=android.app.searchable
            机器人:资源=@ XML /搜索/&GT;

        &LT;意向滤光器&gt;
            &lt;作用机器人:名称=android.intent.action.VIEW/&GT;

            &LT;类机器人:名称=android.intent.category.DEFAULT/&GT;
            &LT;类机器人:名称=android.intent.category.BROWSABLE/&GT;

            &lt;数据
                机器人:计划=HTTP
                机器人:主机=example.com
                机器人:路径preFIX =/小玩意/&GT;
        &所述; /意图滤光器&gt;
    &LT; /活性GT;
 

我有没有做任何明显的错误?

解决方案

编辑:

确定首先确保你的包是可到达亚洲开发银行:

 亚行外壳上午开始-n com.example.simon.test / .activities.MainActivity
 

然后接受多个数据标签,你需要不同的意图过滤器(这是它为我工作不像我所见过的在网络上其他的例子的方式的)。例如:

 &LT;意向滤光器&gt;
    ...
    &lt;数据机器人:计划=HTTP
          机器人:主机=example.com/&GT;
&所述; /意图滤光器&gt;
&LT;意向滤光器&gt;
    ...
    &lt;数据机器人:计划=HTTP
          机器人:主机=example.com
          机器人:路径preFIX =/小玩意/&GT;
&所述; /意图滤光器&gt;
 

注意,在上面的例子中的路径preFIX开始于一个的正斜杠的!

我不知道为什么谷歌的Docs是如此误导或也许这是一些不同版本的亚行,但上述变化完全为我工作。这有助于:来源


这是我做了Chrome浏览器的路线具体联系到我的应用程序:

 &LT;活动
    机器人:名称=。activities.DeepLinkActivity
    机器人:标签=@字符串/ APP_NAME&GT;
    &LT;! - 接受镀铬环节 - &GT;
    &LT;意向滤光器&gt;
        &lt;作用机器人:名称=android.intent.action.VIEW/&GT;
        &LT;类机器人:名称=android.intent.category.DEFAULT/&GT;
        &LT;类机器人:名称=android.intent.category.BROWSABLE/&GT;
        &lt;数据机器人:计划=HTTP
              机器人:主机=example.com
            机器人:路径preFIX =//&GT;
    &所述; /意图滤光器&gt;
    &LT;! - 接受亚行数据标志 - &GT;
    &LT;意向滤光器&gt;
        &lt;作用机器人:名称=android.intent.action.VIEW/&GT;
        &LT;类机器人:名称=android.intent.category.DEFAULT/&GT;
        &LT;类机器人:名称=android.intent.category.BROWSABLE/&GT;
        &lt;数据机器人:计划=HTTP
              机器人:主机=example.com/&GT;
    &所述; /意图滤光器&gt;
&LT; /活性GT;
 

注意第1过滤器适用于谷歌浏览器,而第二一部作品在亚洲开发银行。

注2 的应用程序选择菜单中不会如果链路输入到浏览器的地址栏中显示。它的是一个&LT; A HREF =htt​​p://example.com&GT;&LT; / A&GT; 侧连接部分页。

在我看来,这里的一切是相当模糊的,真的。我没有料到这一切工作。但是,这是它的工作原理我的设备上。希望这有助于(和作品)为您了。

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:

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

I just get

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

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

Have I made any obvious mistakes?

解决方案

EDIT:

Ok first make sure that your package is reachable by adb:

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

Then to accept multiple data tags you need different intent filters (that's the way it worked for me unlike all the other examples I've seen on the net). E.g.:

<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 that in the above example the pathPrefix starts with a forward slash !

I am not sure why Google's Docs are so misleading or maybe that was for some different version of adb, but the above changes worked perfectly for me. This helped: Source


This is how I made the Chrome browser route specific links to my app:

<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 The 1st filter works on Google Chrome while the 2nd one works on the ADB.

NOTE2 The app choice menu won't be shown if the link is entered into the browser's address bar. It has to be a <a href="http://example.com"></a> link in side some page.

In my opinion everything here is rather blurry and really not how I expected it all to work. But that's how it works on my device. Hope this helps (and works) for you too.

这篇关于深联的意图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆