网页启动Android APK

点击网页中的URL链接,打开手机中已经存在的Android应用。

网页中URL格式:

<a href="[scheme]://[host]/[path]?[query]">打开app</a>

例:<a href="cbg://android.apk/">打开app</a>

scheme:启动app的标识,必须有;

host:有无不影响启动;

path:有无不影响启动;

query:获取值的key和value,有无不影响启动。


Android端,在AndroidManifest.xml中的MainActivity的注册信息中添加如下代码

<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="cbg" 

                    android:host="android"/>

</intent-filter>

:新添加的<intent-filter>的内容不可也原有的<intent-filter>的内容混合在一个<intent-filter>中,要使用两个<intent-filter>。


数据传递:

使用URL添加参数的方式

如:<a href="cbg://android.apk/login?page=0&num=1">打开app</a>


Android端获取数据

Intent intent = getIntent();

String page,num;

Uri uri = intent.getData();

if(uri!=null){

      page=uri.getQueryParameter("page");

      num=uri.getQueryParameter("num")

}


相关链接:

http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app

http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容