经过html调用App并传送参数倒App中

忽然有一天玩360手机助手下载东西,可是点击安装直接就跳转到App中,卧槽,这比较新奇,之前真没以为有这么一回事,才疏学浅呐。html

1、经过html页面打开Android本地的appandroid

简单的html页面web

<html> 浏览器

    <head>app

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>ide

    </head>ui

    <body>url

        <a href="m://my.com/">打开app</a><br/>htm

    </body>webview

</html>

二、在Android本地app的配置

在AndroidManifest的清单文件里的intent-filte中加入以下元素:
<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="my.com"
                    android:scheme="m" />
</intent-filter>

2、如何经过这个方法获取网页带过来的数据能

能打开好像就那么回事,可是能传数据就牛X了

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <a href="m://my.com/?arg0=0&arg1=1">打开app</a><br/>
    </body>
</html>

(1).假如你是经过浏览器打开这个网页的,那么获取数据的方式为:

Uri uri = getIntent().getData();  String test1= uri.getQueryParameter("arg0");  String test2= uri.getQueryParameter("arg1");

(2)若是使用webview访问该网页,获取数据的操做为:

webView.setWebViewClient(new WebViewClient(){   @Override   public boolean shouldOverrideUrlLoading(WebView view, String url) {       Uri uri=Uri.parse(url);           if(uri.getScheme().equals("m")&&uri.getHost().equals("my.com")){               String arg0=uri.getQueryParameter("arg0");               String arg1=uri.getQueryParameter("arg1");           }else{               view.loadUrl(url);           }       return true;   } });

相关文章
相关标签/搜索