1.在清单文件中添加过滤
<activity
android:name=".mvp.ui.activity.Index"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/ThemeSplash"
android:windowSoftInputMode="stateHidden|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="jp.app"
android:pathPrefix="/openwith"
android:scheme="myapp" />
</intent-filter>
</activity>
2.准备.html点击事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="myapp://jp.app/openwith?name=zhangsan&age=26">打开app</a><br/>
</body>
</html>
3.接收传参
Intent intent = getIntent();
if (intent != null) {
String act = intent.getAction();
if (Intent.ACTION_VIEW.equals(act)) {
Uri uri = intent.getData();
if (uri != null) {
String host = uri.getHost();
String queryString = uri.getQuery();
Log.e("enenennenen:", host + "");
Log.e("enenennenen:", queryString + "");
String test1 = uri.getQueryParameter("name");
String test2 = uri.getQueryParameter("age");
Log.e("enenennenen:", test1 + "");
Log.e("enenennenen:", test2 + "");
}
}
}