Android其他

浏览器启动APP

2017-10-11  本文已影响0人  沅兮
做一个测试的html页面
<a href="[scheme]://[host]/[path]?[query]">start APP</a>
> scheme:判别启动的app。
> host:标记
> path:传值时必须的key(可以没有)
> query:获取值的key和value(可以没有)
<a href="app://com.app/openwith?name=lbj&age=18">start APP</a>
Android端改写
<intent-filter>  
    <action android:name="android.intent.action.MAIN"/>  
    <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="app" android:host="com.app" android:pathPrefix="/openwith"/>  
</intent-filter>
> 上面有两个<intent-filter>,一个用于app自己启动,一个用于浏览器打开,必须分开写
> <data>标签中的scheme和host必须对应html中设置的数据,且scheme内容必须为小写
在app中获取html传过来的值
Intent intent= getIntent();  
String action = intent.getAction();  
  
if(Intent.ACTION_VIEW.equals(action)){  
    Uri uri = intent.getData();  
    if(uri != null){  
        String name = uri.getQueryParameter("name");  
        String age= uri.getQueryParameter("age");  
    }  
}
浏览器启动app
上一篇 下一篇

猜你喜欢

热点阅读