【问题标题】:Android deep linking not working on webviewAndroid 深度链接在 webview 上不起作用
【发布时间】:2016-11-03 09:02:49
【问题描述】:

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

<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 中运行,但不能在 web 视图中运行(总是相同的“err_unknown_url_scheme”)

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

我在意图上阅读了Android documentation,也尝试过类似的方法,但我不确定它是否正确

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

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

非常感谢!

【问题讨论】:

  • 您应该删除“动作”部分并将其移至意图部分。 &lt;a href="intent://deeplink?showStore=001/#Intent;scheme=myapp;package=com.example.myapp;end"&gt;Open in app&lt;/a&gt;
  • @SimonMarquis 无法在 webview 中工作,我会向应用程序的开发人员反馈,您的意图看起来不错,并且可以在 webview 之外工作。谢谢!
  • 对于webviews,必须在WebView客户端处理(shouldHandleUrl方法或类似方法)

标签: android html webview deep-linking


【解决方案1】:
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>

如果这些对你不起作用,请告诉我。

【讨论】:

  • 谢谢 jitesh,我说的问题是我无法访问应用程序代码,我是网页的开发人员......我会用你的例子回到开发人员那里,对我来说看起来很棒,谢谢!
  • 名声还不够,抱歉?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多