android webview(外部浏览器)调起app

  最近写的项目中涉及外部浏览器以及项目webview中调起app,所以总结下,和大家分享下。

  总的实现方法还是比较简单的,

  1:在清单中注册

  首先在AndroidManifest文件中,注册一个过滤器

 

<intent-filter >
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="xxx" android:host="xxx"/>
</intent-filter>

其中scheme和host如下:

scheme://host:port/path

例如:nearbar://com.nearbar.android:200/folder/subfolder/etc 
\---------/  \---------------------------/ \---/ \--------------------------/ 
scheme                 host               port        path 
                \--------------------------------/ 
                          authority    

2:在mainactivity中接收

  

if (Intent.ACTION_VIEW.equals(action)) {
Uri uri = i_getvalue.getData();
String data = uri.toString();

}

由于我的项目中url中传过来的是json串,通过解析来判断具体的操作。

 

posted @ 2016-06-14 12:18  夏沫琅琊  阅读(3569)  评论(0编辑  收藏  举报