Android应用程式连结无法正常运作 [英] Android app link is not working fine

查看:117
本文介绍了Android应用程式连结无法正常运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用应用链接进行测试,但是它在我的作品中不起作用案件。

I've been playing with app links with a test example but it's not working in my case.

我在资产目录中创建了两个HTML文件 source.html some_html_file.html 。 m在网络视图中加载source.html文件,该文件具有按钮,我正在使用该按钮导航到 some_html_file.html 。查看资料来源,您将了解我在这里做什么。

I've created two html files source.html and some_html_file.html within the assets directory.I'm loading source.html file within a webview and that has button and I'm navigating to some_html_file.html using that button. See the source you'll get to know what I'm doing here.

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> 标签,并将显示具有逻辑的活动处理意图。

So clicking the first button, I'm expecting that android os should read the <meta> tags of the target html file and will show my activity which has the logic to handle the intent.

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>

任何帮助将不胜感激。

Any help would be appreciated.

从logcat中可以看到-

From the logcat I can see that -


D / WebViewCallback:shouldOverrideUrlLoading = file:///android_asset/some_html_file.html?
W / WebViewCallback:没有应用程序可以处理file:///android_asset/some_html_file.html?

D/WebViewCallback: shouldOverrideUrlLoading=file:///android_asset/some_html_file.html? W/WebViewCallback: No application can handle file:///android_asset/some_html_file.html?

更新:

我已经更新了我的问题。我刚刚添加了一个带有操作的表格。检查 source.html 中的表单 type_2 。按钮为示例2-转到新闻23 正常,并且我在 HandleUriActivity 活动中获取了以下数据。

I've updated my question. I've just added one more form with action. Check form type_2 in source.html. Button is Example 2 - go to news 23 is working fine and I'm getting the following data on HandleUriActivity activity.

host = node
authority = node
path = /news/23

我的问题是我该如何处理第一种情况,即android操作系统应该在打开具有元数据标签的页面(some_html_file.html)时打开我的活动。

更新#2

我确实同意您 @Eric B 。但是如果我使用其他应用程序,则无法正常工作。

I do agree with you @Eric B. But It is not working if I've a different app.

我在测试网站上拥有一个包含以下元数据的网页。

I've a webpage with the following meta data on my test website.

<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浏览器没有显示我的应用。它直接打开网页。

When I'm opening this page within Google Chrome, Chrome didn't show my app. It directly opens the webpage.

推荐答案

实现深层链接的动机是,当链接被打开时,应打开您的应用程序。在另一个浏览器中单击。对于您的浏览器(WebView),您的应用程序中没有使用深度链接的意义,您可以使用以下代码简单地打开您的特定活动:

Deep Linking is implemented with the motive in mind that your app should be opened when a link is clicked in another browser. In your case your browser (WebView) exists within your app, which doesn't make sense of using Deep Linking, you could simply open up your particular activity using this code:

webView.setWebViewClient(new WebViewClient() { 
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                if(url.equals(YOUR_URL))
                {
                   // Open Activity here
                }
                webView.loadUrl(url); 
                return false; 
            } 
        });

您可以看到我的答案此处关于深度链接。

You can see my answer here regarding Deep Linking.

更新

像这样更改清单:

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

这篇关于Android应用程式连结无法正常运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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