美文网首页
Android网页链接打开本地app

Android网页链接打开本地app

作者: 小婷婷tt | 来源:发表于2020-11-12 14:04 被阅读0次

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 + "");
                }
            }
        }

相关文章

网友评论

      本文标题:Android网页链接打开本地app

      本文链接:https://www.haomeiwen.com/subject/djqpbktx.html