美文网首页Android技术
Android 使用URL链接打开App

Android 使用URL链接打开App

作者: CRAZYSNAIL_c105 | 来源:发表于2017-12-06 15:20 被阅读797次

实现一下浏览器通过通过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

相关文章

网友评论

    本文标题:Android 使用URL链接打开App

    本文链接:https://www.haomeiwen.com/subject/lfnkixtx.html