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串,通过解析来判断具体的操作。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM