前端通过URL scheme打开手机内APP

前端通过URL scheme打开手机内APP

需求:网页上一个链接,点击后会唤醒手机内响应的app,打开指定APP的功能页面。

方法:在AndroidManifest.xml里面对需要打开的页面设置action,两个category, data

<activity android:name=".MainActivity2">
    <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="fshao" android:host="my.app" android:pathPrefix="/openwith"/>
    </intent-filter>
</activity>

一会儿url请求格式是: scheme://host/path?传的参数

对应页面获取数据:

kotlin:

val uri = intent.data
if(uri != null){
    val url = uri.toString()
    val scheme = uri.scheme
    val host = uri.host
    val port = uri.port
    val path = uri.path
    val pathSegments = uri.pathSegments
    val query = uri.queryParameterNames

    for (key in query){
        showText = showText + key + ":" + uri.getQueryParameter(key) + "\n"
    }
    tv_show.setText(showText)
}

java

见这个大佬的博客:https://www.cnblogs.com/chaoyuehedy/p/9004224.html

本文也是看这个博客,记录一下。

猜你喜欢

转载自blog.csdn.net/qq_36571422/article/details/113523513