美文网首页
Html中启动本地app

Html中启动本地app

作者: lotusve_w | 来源:发表于2019-08-21 08:34 被阅读0次
    1. 前言:

    html中启动本地app

    1. html:

    <a href="appscheme://apphost/openwith?name=zhang3&age=30">Start App</a>
    

    格式: [scheme]://[host]/[path]?[query]
    html代码:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>Start App</title>
        </head>
        <body>
            <a href="appscheme://apphost/openwith?name=zhang3&age=30">Start App</a>
        </body>
    </html>
    
    1. android 代码

    AndroidManifest.xml中, 在要启动的Activity中添加如下:

    <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="appscheme" android:host="apphost" android:pathPrefix="/openwith"/>  
    </intent-filter>
    

    获取参数, 启动的Activity中:

    try {
        Uri uri = getIntent().getData();
        String query = uri.getQuery();
        String name = uri.getQueryParameter("name");
        String age = uri.getQueryParameter("age");
        Log.d("appscheme-", "name: " + name + ", age: " + age + ", query: " + query);
    } catch (Exception e) {
        Log.e("appscheme-", e.getMessage(), e);
    }
    

    相关文章

      网友评论

          本文标题:Html中启动本地app

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