【发布时间】:2016-03-19 13:44:09
【问题描述】:
我一直在使用app links 测试示例,但它不适用于我的情况。
我在资产目录中创建了两个 html 文件 source.html 和 some_html_file.html。我正在 webview 中加载 source.html 文件,并且按钮,我正在使用该按钮导航到 some_html_file.html。查看源代码,您将了解我在这里做什么。
source.html
<html>
<form name = "type_1" action="some_html_file.html">
<input type="submit" value="Example 1 - open some html file"/>
</form>
<form name = "type_2" action="example2://node/news/23">
<input type="submit" value="Example 2 - go to news 23"/>
</form>
</html>
some_html_file.html
<html>
<head>
<meta property="al:android:url" content="example://node/news/23" />
<meta property="al:android:package" content="com.example.uritest" />
<meta property="al:android:app_name" content="UriTest" />
</head>
<h3>This is uri test page.</h3>
</html>
问题
所以单击第一个按钮,我希望 android 操作系统应该读取目标 html 文件的 <meta> 标记,并将显示我的活动,该活动具有处理意图的逻辑。
AndroidManifest.xml
<activity android:name=".HandleUriActivity">
<intent-filter>
<data
android:scheme="example"
/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<data
android:scheme="example2"
/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
任何帮助将不胜感激。
从 logcat 我可以看到 -
D/WebViewCallback: shouldOverrideUrlLoading=file:///android_asset/some_html_file.html? W/WebViewCallback:没有应用程序可以处理 file:///android_asset/some_html_file.html?
更新:
我更新了我的问题。我刚刚添加了另一种带有操作的表单。检查 source.html 中的表单 type_2。按钮是示例 2 - 转到新闻 23 工作正常,我正在获取以下关于 HandleUriActivity 活动的数据。
host = node
authority = node
path = /news/23
我的问题是如何处理第一种情况,即 android 操作系统应该在打开具有元数据标签的页面(some_html_file.html)时打开我的活动。
更新 #2:
我同意你的看法@Eric B。但如果我有不同的应用程序,它就不起作用。
我的测试网站上有一个包含以下元数据的网页。
<head>
<meta property="al:android:url" content="example://node/news/23" />
<meta property="al:android:package" content="com.example.uritest" />
<meta property="al:android:app_name" content="UriTest" />
</head>
当我在 Google Chrome 中打开此页面时,Chrome 没有显示我的应用。直接打开网页。
【问题讨论】:
标签: android deep-linking applinks