点击浏览器中的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. Angularjs 双向绑定机制解析
  2. ready与onload的性能
  3. 诡异的 未处理的IOErrorEvent 2035
  4. ASP.NET MVC 网站开发总结(四)——校友平台开发总结
  5. Web 开发中应用 HTML5 技术的10个实例教程
  6. 转载:最大子段和问题(Maximum Interval Sum)
  7. Swift给每个开发者赢取500万的机会!不看一生后悔。
  8. poj 2661 Factstone Benchmark (Stirling数)
  9. python编程语言缩进格式
  10. win7下VS.NET中通过LinqToSQL连接oracle数据库
  11. Java基础知识强化之集合框架笔记47:Set集合之TreeSet保证元素唯一性和比较器排序的原理及代码实现(比较器排序:Comparator)
  12. linux 删除和安装java
  13. Java并发之CountDownLatch、CyclicBarrier和Semaphore
  14. Bootstrap各种进度条的实例讲解
  15. linux一台服务器配置多个Tomcat
  16. LR运行负载测试场景-笔记
  17. Java语法基础常见疑惑解答8,16,17,21图片补充
  18. 工程部署从tomcat6.0迁移到jboss6.0错误总结
  19. 我的notepad++
  20. 【线程】Volatile关键字

热门文章

  1. 【BZOJ1072】排列(搜索)
  2. 【poj3420】 Quad Tiling
  3. docker attach 和 docker exec
  4. [CQOI2012] 交换棋子 (费用流)
  5. python之旅:绑定方法与非绑定方法
  6. SenseTime Ace Coder Challenge 暨 商汤在线编程挑战赛 E. 疯狂计数
  7. 树状数组+二分答案查询第k大的数 (团体程序设计天梯赛 L3-002. 堆栈)
  8. 关于maven工程打jar的问题
  9. 2018java面试集合
  10. MySQL内存计算器