Android本地应用打开方法——通过html5写连接

2022-10-18,,,,

1、在html中设置链接

复制代码代码如下:
href=”[scheme]://[host]/[path]?[query]”

scheme可以自己在app内部设置成任意的,把android和ios的设置成一样的
2、若本地应用存在,直接打开app;若不存在,计时一段时间跳到appstore
需要判断ios还是android平台下的浏览器,需要判断微信浏览器

xml/html code复制内容到剪贴板

  1. <code class="hljs" javascript="">var openapp = function () {    
  2. var btnopenapp = document.getelementbyid(open-app);    
  3. btnopenapp.onclick = function () {    
  4. //打开本地应用函数    
  5. var open=function(url){    
  6. var timeout;    
  7. function try_to_open_app() {    
  8. timeout = settimeout(function(){    
  9. window.location.href=url;    
  10. console.log()    
  11. }, );    
  12. }    
  13. try_to_open_app();    
  14. }    
  15. if (/android/i.test(navigator.useragent)) {    
  16. //alert(this is android'browser.);//这是android平台下浏览器    
  17. if (/micromessenger/i.test(navigator.useragent)) {    
  18. alert(this is micromessenger browser,请使用本地浏览器打开);//这是微信平台下浏览器    
  19. }    
  20. else {    
  21. open(andorid应用市场url);    
  22. }    
  23. }    
  24. if (/(iphone|ipad|ipod|ios)/i.test(navigator.useragent)) {    
  25. //alert(this is ios'browser.);//这是ios平台下浏览器    
  26. if (/micromessenger/i.test(navigator.useragent)) {    
  27. alert(微信内置浏览器不支持打开本地应用,请点击右上角使用本地浏览器打开);//这是微信平台下浏览器    
  28. }    
  29. else {    
  30. open(ios应用市场url);    
  31. }    
  32. }    
  33. };    
  34. }</code>   

 android配置

xml/html code复制内容到剪贴板

  1. <activity android:name=".ui.uploadactivity" android:screenorientation="portrait">    
  2. <intent-filter>    
  3. <data android:scheme="http" android:host="192.168.167.33" android:port="8088" android:path="/mi-tracker-web/download.html">    
  4. <action android:name="android.intent.action.view">    
  5. <category android:name="android.intent.category.default">    
  6. <category android:name="android.intent.category.browsable">    
  7. </category></category></action></data></intent-filter>    
  8. </activity>   

open application

xml/html code复制内容到剪贴板

  1. <%@ page language="java" contenttype="text/html; charset=iso-8859-1"    
  2. pageencoding="iso-8859-1"%>    
  3. <script type="text/javascript"> window.location="market://search?q=com.singtel.travelbuddy.android";</script>    
  4. string str = "market://details?id=" + getpackagename();    
  5. intent localintent = new intent("android.intent.action.view");    
  6. localintent.setdata(uri.parse(str));    
  7. startactivity(localintent);   

html配置示例
open app
open market
open market details
android获取参数:

xml/html code复制内容到剪贴板

  1. uri uri = getintent().getdata(); string test1uri.getqueryparameter("arg0"); string test2uri.getqueryparameter("arg1");    
  2. webview.setwebviewclient(new webviewclient(){    
  3. @override    
  4. public boolean shouldoverrideurlloading(webview view, string url) {    
  5. uri uri=uri.parse(url);    
  6. if(uri.getscheme().equals("m")&&uri.gethost().equals("my.com")){    
  7. string arg=uri.getqueryparameter("arg");    
  8. string arg=uri.getqueryparameter("arg");    
  9. }else{    
  10. view.loadurl(url);    
  11. }    
  12. return true;    
  13. }    
  14. });  

以上所述是小编给大家介绍的android本地应用打开方法——通过html5写连接 ,希望对大家有所帮助!

《Android本地应用打开方法——通过html5写连接.doc》

下载本文的Word格式文档,以方便收藏与打印。