您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页Android 使用URL链接打开App

Android 使用URL链接打开App

来源:二三娱乐

实现一下浏览器通过通过URL打开指定的APP功能。

  1、安卓设备已安装APP,打开App并跳到指定的的页面。
  2、安卓设备未安装APP,跳转到下载页下载。

实现步骤:

1、在AndroidManifest.xml 文件中,找到浏览器意图跳转的的Activity视图对应的<activity />标签,在标签下加<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:scleme="myApp"
    android:host="127.0.0.1:8080"
    pathPerfix="/openwith"
   />
</intent-filter>

2、HTML链接中使用格式:[scheme]://[host]/[path]?[query] 。
   scheme:判断启动的App。
   host:类似于标识,(可以不使用)
   path:传值是必须的Key,对应安卓中pathPrefix (可以不使用)
   query:参数列,可以不使用。
示例:

<a href="myapp://jp.app/openwith?name=zhangsan&age=26">打开App</a>

2、获取参数

//链接中取值取值
Intent i_getvalue = getIntent();
String action = i_getvalue.getAction();
if(Intent.ACTION_VIEW.equals(action)){
  Uri uri = i_getvalue.getData();
  if(uri != null){
     String name = uri.getQueryParameter("name");
     String age= uri.getQueryParameter("age");
    textView.setText("地址:"+uri.toString()+"\n姓名"+name+"\t年龄"+age);
   }
}

注意:一些特别的浏览器是无法实现URL打开App

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务