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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。