[英]Android app link is not working fine
我一直在玩带有测试示例的应用程序链接 ,但它在我的情况下不起作用。
我在assets目录中创建了两个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 os应该读取目标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 os应该在打开包含元数据标签的页面(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>
当我在谷歌浏览器中打开此页面时,Chrome没有显示我的应用。 它直接打开网页。
实施深度链接的动机是,在另一个浏览器中单击链接时应打开您的应用程序。 在您的情况下,您的浏览器(WebView)存在于您的应用程序中,使用深层链接没有意义,您只需使用以下代码打开您的特定活动:
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(url.equals(YOUR_URL))
{
// Open Activity here
}
webView.loadUrl(url);
return false;
}
});
您可以在此处查看有关深层链接的答案。
UPDATE
像这样更改你的清单:
<activity android:name=".HandleUriActivity">
<intent-filter>
<data android:scheme="http"
android:host="rahulchaurasia3592.github.io" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.