简体   繁体   English

Android深层链接无法在WebView上运行

[英]Android deep linking not working on webview

I'm facing an issue with deep linking and Android filters. 我遇到了深层链接和Android过滤器的问题。 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>

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") 当我尝试通过常规链接打开应用程序时,它可以在Android Chrome浏览器中使用,但不能在Webview中使用(总是相同的“ err_unknown_url_scheme”)

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

I read Android documentation on intents, and also tried something like this, but I'm not sure if it is correct 我阅读了有关意图的Android文档 ,还尝试了类似的方法,但是我不确定它是否正确

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

I only have access to the HTML code, not the Android app code. 我只能访问HTML代码,而不能访问Android应用程序代码。 My goal is to click that link and open myapp. 我的目标是单击该链接并打开myapp。 All stackoverflow questions about this topic are Android development related or other posts over internet are a little bit old-fashioned. 关于此主题的所有stackoverflow问题都与Android开发相关,或者其他Internet上的帖子有些过时。

Much appreciated! 非常感激!

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. 请让我知道这些方法是否不适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM