【问题标题】:How to Enable Deep-Linking on a WebView Application如何在 WebView 应用程序上启用深度链接
【发布时间】:2021-01-05 20:08:50
【问题描述】:

我的应用程序是 WebView 应用程序,并且我设置了 URL Intent 过滤器,因此当单击域“riftacademy.org”的链接时,它会打开我的应用程序。

现在我正在尝试在 WebView 应用程序中实现深度链接...

我在How to enable deep-linking in WebView on Android app?的线程中看到了类似的东西

但与上面使用自定义 URI 方案打开应用程序不同,我想使用我的域名“riftacademy.org”在我的 WebView 中实现深度链接

在这种情况下,当单击https://riftacademy.org/loginhttps://riftacademy.org/register 等链接时,它应该打开应用程序并转到与链接匹配的页面。但在这种情况下,它会打开应用程序但只加载主页 riftacademy.org...

我希望 WebView 应用能够在应用打开后加载链接,类似于 YouTube 和 Facebook 处理链接的方式

可以在 WebView 中使用域名实现 Deep-Linking 吗?

可能需要我猜测的位置的 sn-p 来编辑

newWebView.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        Intent browserIntent = new Intent(Intent.ACTION_VIEW);
                        browserIntent.setData(Uri.parse(url));
                        startActivity(browserIntent);
                        return true;
                    }
                });
                return true;
            }
        });

提前致谢

【问题讨论】:

    标签: android webview android-webview


    【解决方案1】:

    所以我已经能够在来自https://webintoapp.com 的 Ron 的帮助下解决这个问题......这是使用 URI Intent Filters 并将以下代码放在 MainActivity.java 和 AndroidManifest.xml 中实现的

    我将此添加到我的 MainActivity.java 中的 OnCreate 方法中...网站名称应在 else{mWebView.loadUrL

    之后添加
    SetWebView(mWebView);
            Intent intent = getIntent();
            Uri data = intent.getData();
            if(data != null) {
                //Load the deep-link url:
                String url = intent.getDataString();
                mWebView.loadUrl(url);
            }
            else
            {
                mWebView.loadUrl("https://riftacademy.org/");
            }
    

    这是我的 MainActivity.xml... android:host 也应该是网站 URL

    <activity android:name=".MainActivity">
                <intent-filter android:label="The Title">
                    <action android:name="android.intent.action.VIEW" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
    
                    <data
                        android:scheme="https"
                        android:host="riftacademy.org" />
                </intent-filter>
                <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:scheme="http"
                        android:host="riftacademy.org" />
    

    这将使 WebView App 能够加载各种链接,只要链接以网站的​​默认 URL 开头

    【讨论】:

      猜你喜欢
      • 2014-10-29
      • 2021-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多