网页启动Android APK

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

网页中URL格式:

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

  
  
  • 1
  • 2

例:

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

  
  
  • 1
  • 2

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

host:有无不影响启动;

path:有无不影响启动;

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

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

      <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"/>

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

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

数据传递:

使用URL添加参数的方式

如:

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

  
  
  • 1
  • 2

Android端获取数据:

Intent intent = getIntent();

String page,num;

Uri uri = intent.getData();

if(uri!=null){

  page=uri.getQueryParameter(“page”);

num=uri.getQueryParameter(“num”)

猜你喜欢

转载自blog.csdn.net/anyanyan07/article/details/78982699