通过Html网页调用本地安卓(android)app程序代码

一、通过html页面打开Android本地的app

1、首先在编写一个简单的html页面

复制代码 代码如下:

   

       

        Insert title here

   

   

        打开app

   


2、在Android本地app的配置

复制代码 代码如下:

在AndroidManifest的清单文件里的intent-filte中加入如下元素:
 

               
               

                                    android:host="my.com"
                    android:scheme="m" />

示例截图如下:

然后使用“手机浏览器”或者“webview”的方式打开这个本地的html网页,点击“打开APP”即可成功开启本地的指定的app

二、如何通过这个方法获取网页带过来的数据

只能打开就没什么意思了,最重要的是,我们要传递数据,那么怎么去传递数据呢?

我们可以使用上述的方法,把一些数据传给本地app,那么首先我们更改一下网页,代码修改后:

复制代码 代码如下:


   
       
        Insert title here
   
   
        打开app

   

(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;
  }
});

你可能感兴趣的:(通过Html网页调用本地安卓(android)app程序代码)