URL Scheme作为android中拉起app的一种方式,还是比较常见的

好处

  • 可以从网页中拉起app
  • 可以拉起具体Activity

说明

android通过url scheme打开activity,只需要在manifest 中配置以下几个参数即可

                                        "***"                    android:path="***"                    android:scheme="***">                                ...

实际上 中还有其他参数,若有复杂的需求可以研究下。

这里看下这几个参数就可以了,可以参考url格式

android:scheme 协议类型android:host 主机地址android:path 具体路径

android:scheme="http"android:host="www.baidu.com"android:path="/s"http://www.baidu.com/s?wd=what这样的链接在浏览器中也可以直接访问的

举个例子

在activity中加入<intent-filter>    <data        android:host="www.adc.com"        android:path="/person"        android:scheme="myapp"/>        <action android:name="android.intent.action.VIEW"/>        <category android:name="android.intent.category.DEFAULT"/>        <category android:name="android.intent.category.BROWSABLE"/>intent-filter>

这样通过链接 myapp://www.abc.com/person 就可以打开此activity了;
可以再复杂些,比如打开activity打开某个用户的信息 myapp://www.abc.com/person?id=123

从html网页中启动app

让另一个app显示其中的人员信息,那只要传入一个id就可以了
在html中,直接使用url链接启动app,并且可以打开具体的activity

<a href="myapp://www.abc.com/person?id=123&search=https://www.baidu.com/s?wd=what">start appa>

从java代码中启动app

Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("myapp://www.abc.com/person?id=123&search=https://www.baidu.com/s?wd=what"));startActivity(intent);

解析传入的参数

Intent intent = getIntent();String action = intent.getAction();if(Intent.ACTION_VIEW.equals(action)){   Uri uri = intent.getData();   if(uri != null){      String id = uri.getQueryParameter("id"); // id="123"      String search = uri.getQueryParameter("search"); // search="https://www.baidu.com/s?wd=what"   }}

更多相关文章

  1. android线性布局参数详解
  2. Android 导入多个外部静态链接库, 进行动态库编译方法( NDK)
  3. ndk下载链接汇总
  4. android知识链接汇总(3)
  5. android_relative布局参数学习
  6. android交叉编译工具链接下载
  7. Android 模拟器创建参数说明
  8. Android超链接去下划线--Android学习笔记6-4
  9. 参数设置

随机推荐

  1. Android应用程序注冊广播接收器(registerR
  2. android每日一问1【2011-09-08】
  3. 深入理解Android消息处理系统——Looper
  4. androidManifest.xml之uses-permission(
  5. Android(安卓)启动过程分析 (一)
  6. android Fragments详解一:概述
  7. Android(安卓)GPS (当前位置 & GPS信息更
  8. Android(安卓)USB配件模式
  9. Android——ListView控件(Android(安卓)S
  10. Android(安卓)root原理