点击浏览器中的URL链接,启动特定的App。

首先做成HTML的页面,页面内容格式如下:

<a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> 

这一句就可以了。

各个项目含义如下所示:

scheme:判别启动的App。 ※详细后述

host:适当记述

path:传值时必须的key ※没有也可以

query:获取值的Key和Value ※没有也可以

作为测试好好写了一下,如下:

<a href="myapp://jp.app/openwith?name=zhangsan&age=26">启动应用程序</a>  

接下来是Android端。
首先在AndroidManifest.xml的MAIN Activity下追加以下内容。(启动Activity时给予)

※必须添加项

<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:scheme="myapp" android:host="jp.app" android:pathPrefix="/openwith"/>  </intent-filter>

HTML记述的内容加入<data …/>。
其中必须的内容仅scheme,没有其他内容app也能启动。

※注意事项:intent-filter的内容【android.intent.action.MAIN】和 【android.intent.category.LAUNCHER】这2个,不能与这次追加的内容混合。
所以,如果加入了同一个Activity,请按以下这样做,否则会导致应用图标在桌面消失等问题。

<intent-filter>      <action android:name="android.intent.action.MAIN"/>      <category android:name="android.intent.category.LAUNCHER" />  </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:scheme="myapp" android:host="jp.app" android:pathPrefix="/openwith"/>  </intent-filter> 

这样的话,没有问题。

接下来在Activity中需要取值的地方添加以下代码,我是直接写在OnCreate函数里的:

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");      }  }  

这样就能获取到URL传递过来的值了。

更多相关文章

  1. Android欢迎界面的创建方法
  2. Android(安卓)7.0 ActivityManagerService(1) AMS的启动过程
  3. Android中启动其他Activity并返回结果
  4. 2010.06.04日志:关于android正在运行程序的关闭问题
  5. android:imx8qm平台下spi_norflash启动kernel
  6. Android判断app是不是第一次启动
  7. # Android中Activity四种启动模式和taskAffinity属性详解 #(6原
  8. android文件下载进度条实现
  9. android 开机自启动的几种方法,监听不到RECEIVE_BOOT_COMPLETED的

随机推荐

  1. Android(安卓)中右上角菜单创建(Menu)
  2. 详解android的号码匹配
  3. Android(安卓)性能优化杂谈(开篇)
  4. Android破解锁屏密码(已root)
  5. Android(安卓)studio和Eclipse分别生成ja
  6. 打造通用的Android下拉刷新组件(适用于Li
  7. Android异步消息处理机制 深入理解Looper
  8. webView程序 第一次加载页面是出现白屏或
  9. Android电话薄
  10. Android(安卓)多线程:使用Thread和Handler