【问题标题】:How to open Deep Links in webview application如何在 webview 应用程序中打开深层链接
【发布时间】:2021-01-26 07:04:44
【问题描述】:

我已经创建了我的 webview 应用程序,并且我在 onCreate 方法中将我的主 URL 加载到了 webview。然后我实现了这样的深层链接:

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ariagp.myapplication">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </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="https" android:host="mysitename.com" />
            </intent-filter>
        </activity>
    </application>

</manifest>

现在,当点击深层链接时,应用将在 webview 主页上打开。 但我想让与深层链接相关的页面打开。

当应用程序本身打开时,打开主页。 解决办法是什么?

【问题讨论】:

    标签: java android android-studio webview deep-linking


    【解决方案1】:

    Activity启动时,在onNewIntent(Intent intent)方法中,从intent获取数据(应该是点击的url——深层链接),类型为uri,然后将该url加载到您已实现的网络视图。

    类似下面的代码:

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Uri data = intent.getData();
            
        webView.loadUrl(data.toString());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-10
      • 2018-02-12
      • 2019-01-20
      • 2016-06-26
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多