Android 深层链接不适用于 webview [英] Android deep linking not working on webview

查看:25
本文介绍了Android 深层链接不适用于 webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了深层链接和 Android 过滤器的问题.这是清单的意图部分.

I'm facing an issue with deep linking and Android filters. This is the manifest's intent part.

<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:host="deeplink"
        android:scheme="myapp"/>
</intent-filter>

当我尝试使用常规链接打开应用程序时,它可以在 Android Chrome 中运行,但不能在 webview 中运行(始终相同的err_unknown_url_scheme")

And when I try to open the app with a regular link it works in the Android Chrome, but not in the webview (always same "err_unknown_url_scheme")

<a href="myapp://deeplink/?action=showStore=001">Open in app</a>

我阅读了关于意图的 Android 文档,也尝试过类似的事情,但是不知道对不对

I read Android documentation on intents, and also tried something like this, but I'm not sure if it is correct

<a href="intent://deeplink/#Intent;scheme=myapp;package=com.example.myapp;action=showStore=001;end">Open in app</a>

我只能访问 HTML 代码,不能访问 Android 应用程序代码.我的目标是单击该链接并打开 myapp.有关此主题的所有 stackoverflow 问题都与 Android 开发相关,或者互联网上的其他帖子都有点过时.

I only have access to the HTML code, not the Android app code. My goal is to click that link and open myapp. All stackoverflow questions about this topic are Android development related or other posts over internet are a little bit old-fashioned.

非常感谢!

推荐答案

please try below example which will open your application from webview.


    public class HTMLActvity extends AppCompatActivity {

        private WebView mWebView;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_htmlactvity);
            mWebView = (WebView) findViewById(R.id.webView1);

            //webView.loadUrl("http://www.google.com");
            mWebView.getSettings().setJavaScriptEnabled(true);
            String customHtml = "<a href=\"https://www.example.com\">Open in app</a>";
            mWebView.loadData(customHtml, "text/html", "UTF-8");
        }
    }

    deep link activity register for www.example.com

  <activity android:name=".DeepLinkActivity">
            <intent-filter android:autoVerify="true">
                <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" />
                <data android:scheme="https" android:host="www.example.com" />
            </intent-filter>

        </activity>

如果这些对您不起作用,请告诉我.

please let me know if these doesen't work for you.

这篇关于Android 深层链接不适用于 webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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