问题
i have created my webview application and i loaded my main url in onCreate method to webview. then i implemented the deep links like this:
My Manifest:
<?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>
Now when the deep links get clicked, the app will open on the webview homepage. But I want to make the page related to the deep link open.
And when the app itself opens, make the home page open. what is the solution?
回答1:
When the activity is launched, in the onNewIntent(Intent intent)
method, get data from intent
(it is supposed to be the url clicked - deep link) which has the type uri
, and then load that url in the web view that you've implemented.
Something like below code:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Uri data = intent.getData();
webView.loadUrl(data.toString());
}
来源:https://stackoverflow.com/questions/64309858/how-to-open-deep-links-in-webview-application