您现在的位置是:网站首页> 编程资料编程资料

Android本地应用打开方法——通过html5写连接 _html5_网页制作_

2023-11-11 269人已围观

简介 这篇文章主要介绍了Android本地应用打开方法——通过html5写连接 的相关资料,需要的朋友可以参考下

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 test2提示: 本文由整理自网络,如有侵权请联系本站删除!
    本站声明:
    1、本站所有资源均来源于互联网,不保证100%完整、不提供任何技术支持;
    2、本站所发布的文章以及附件仅限用于学习和研究目的;不得将用于商业或者非法用途;否则由此产生的法律后果,本站概不负责!

-六神源码网