Mah*_*oni 51 android deep-linking android-manifest android-intent
我按照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
Run Code Online (Sandbox Code Playgroud)
我得到了
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>
Run Code Online (Sandbox Code Playgroud)
我有任何明显的错误吗?
Sim*_*mas 110
编辑:
好的,首先确保adb可以访问您的包:
adb shell am start -n com.example.simon.test/.activities.MainActivity
Run Code Online (Sandbox Code Playgroud)
然后接受多个数据标签你需要不同的意图过滤器(这就像我在网上看到的所有其他例子一样对我有用).例如:
<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>
Run Code Online (Sandbox Code Playgroud)
请注意,在上面的示例中,pathPrefix以正斜杠开头!
我不确定为什么Google的文档会如此误导,或者可能是因为某些不同版本的adb,但上述更改对我来说非常合适.这有助于:来源
这就是我将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>
Run Code Online (Sandbox Code Playgroud)
注意第一个过滤器适用于谷歌浏览器,而第二个过滤器适用于亚行.
注意2如果链接输入浏览器的地址栏,则不会显示应用程序选择菜单.它必须是<a href="http://example.com"></a>某个页面的链接.
在我看来,这里的一切都相当模糊,而且我的预期并非如此.但这就是它在我的设备上的工作方式.希望这对你有帮助(也有效).
Fer*_*nch 15
经过一些测试后,这对我有用:
<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>
Run Code Online (Sandbox Code Playgroud)
单击浏览器中的任何链接(例如" http://www.example.com "," http://www.example.com/ "或" http://www.example.com/whatever ")时都可以使用此功能.与"myschema:// example/whatever"相同.
也可以adb使用此命令(使用任何这些URL):
adb shell am start -W -a android.intent.action.VIEW -d "http://www.example.com" com.example
Run Code Online (Sandbox Code Playgroud)
希望有助于您入门.
当一切正常时,您可能希望pathPrefix为不同的活动配置不同的活动.
就我而言,我在 MainActivity 中放置了深层链接意图过滤器,它也是主启动器。这导致了问题。
在我创建了另一个单独的活动并将意图过滤器放在那里之后,它解决了这个问题。希望这可以帮助面临同样问题的其他人。
就我而言,我使用的是模拟器而不是实际的 USB 连接设备,因此我必须将 -d 更改为 -e,如下所示:
adb shell am start -W -a android.intent.action.VIEW -e "http://www.example.com" com.example
Run Code Online (Sandbox Code Playgroud)
注意深层链接前的-e。
| 归档时间: |
|
| 查看次数: |
57621 次 |
| 最近记录: |