Java 如何在webview应用程序中打开深度链接
我已经创建了我的webview应用程序,并在onCreate方法中将我的主url加载到webview。然后我实现了如下深层链接: 我的舱单:Java 如何在webview应用程序中打开深度链接,java,android,android-studio,webview,deep-linking,Java,Android,Android Studio,Webview,Deep Linking,我已经创建了我的webview应用程序,并在onCreate方法中将我的主url加载到webview。然后我实现了如下深层链接: 我的舱单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ariagp.mya
<?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主页上打开。
但是我想打开与深度链接相关的页面
当应用程序本身打开时,打开主页。
解决方案是什么?当活动启动时,在
onNewIntent(Intent-Intent)
方法中,从Intent
获取数据(应该是点击的url-深度链接),该url具有uri
类型,然后将该url加载到您实现的web视图中
类似下面的代码:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Uri data = intent.getData();
webView.loadUrl(data.toString());
}