美文网首页
外链调起APP页面

外链调起APP页面

作者: 太极1 | 来源:发表于2020-08-13 09:52 被阅读0次

简述:Android 通过URL scheme 实现点击浏览器中的URL链接,启动特定的App,并调转页面传递参数

<a href="[scheme]://[host]/[path]?[query]">启动应用程序</a>

各个项目含义如下所示:

  • scheme:判别启动的App。 - 必填项
  • host:适当记述。- 必填项
  • path:传值时必须的key。 - 非必填项
  • query:获取值的Key和Value。 - 非必填项

例如:
1.定义一个启动APP的html的页面

 <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
    
        <body>
            <br/>
            <!--<a href="[scheme]://[host]/[path]?[query]">启动应用程序</a>-->
            <a href="test://9988?name=Tom&page=10">打开app</a><br/>
    
    </html>

2.AndroidManifest.xml加入需要启动的的页面的配置

  <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:host="9988"
                    android:scheme="test" />
   </intent-filter>

3.获取数据

 private fun getData() {
        if (intent != null) {
            val intentAction = intent.action
            if (Intent.ACTION_VIEW == intentAction) {
                val intentData  = intent.data
                val name = intentData?.getQueryParameter("name")
                val page = intentData?.getQueryParameter("page")
                Log.e("TAG", "initIntentData: $name")
                Log.e("TAG", "initIntentData: $page")
            }
        }
    }

log 如下 大功告成


image.png

相关文章

网友评论

      本文标题:外链调起APP页面

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