首页前端开发HTMLhtml5写链接打开ios和android本地应用

html5写链接打开ios和android本地应用

时间2024-01-26 18:07:02发布访客分类HTML浏览638
导读:收集整理的这篇文章主要介绍了html5教程-html5写链接打开ios和android本地应用,觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。 1、...
收集整理的这篇文章主要介绍了html5教程-html5写链接打开ios和android本地应用,觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

1、在htML中设置链接

href=”[scheme]://[host]/[path]?[query]”

scheme可以自己在app内部设置成任意的,把andROId和ios的设置成一样的

2、若本地应用存在,直接打开app;若不存在,计时一段时间跳到AppStore
需要判断ios还是android平台下的浏览器,需要判断微信浏览器

 VAR oPEnApp = function () {
         var BTnOpenApp = document.getElementById(open-app);
     btnOpenApp.onclick = function () {
         //打开本地应用函数         var open=function(url){
                 var timeout;
                      function try_to_open_app() {
                     timeout = setTimeout(function(){
                         window.location.href=url;
                     console.LOG(22)                        }
    , 10);
                 }
                     try_to_open_app();
         }
           if (/android/i.test(navigator.userAgent)) {
                 //alert(This is Android'browser.);
//这是Android平台下浏览器             if (/Micromessenger/i.test(navigator.userAgent)) {
                     alert(This is MicroMessenger browser,请使用本地浏览器打开);
//这是微信平台下浏览器             }
             else {
                     open(andorid应用市场url);
             }
         }
           if (/(iPhone|iPad|IPOd|iOS)/i.test(navigator.userAgent)) {
                 //alert(This is iOS'browser.);
//这是iOS平台下浏览器             if (/MicroMessenger/i.test(navigator.userAgent)) {
                     alert(微信内置浏览器不支持打开本地应用,请点击右上角使用本地浏览器打开);
//这是微信平台下浏览器             }
             else {
                     open(ios应用市场url);
             }
         }
     }
    ;
 }
       

  Android配置

 activITy android:name=".ui.UploadActivity" android:screen@R_512_221@="portrait">
                 intent-filter>
                     data android:scheme="http" android:host="192.168.167.33" android:port="8088" android:path="/mi-tracker-web/download.html">
                     action android:name="android.intent.action.VIEW">
                     category android:name="android.intent.category.DEFAULT">
                     category android:name="android.intent.category.BROWSABLE">
                 /category>
    /category>
    /action>
    /data>
    /intent-filter>
             /activity>
    
              Open Application
 %@ page language="java" contentType="text/html;
     charset=ISO-8859-1"     pageEncoding="ISO-8859-1"%>
      
script type="text/javascript"> window.location="market://seArch?q=com.singtel.travelbuddy.android"; /script>
 String str = "market://details?id=" + getPackageName();
      Intent localIntent = new Intent("android.intent.action.VIEW");
      localIntent.setData(Uri.parse(str));
      startActivity(localIntent);
    

 HTML配置示例

Open app

Open Market

Open Market Details

Android获取参数:

 Uri uri = getIntent().getData();
      String test1= uri.getQueryParameter("arg0");
      String test2= uri.getQueryParameter("arg1");
  
 webView.setWebViewClient(new WebViewClient(){
   @override   public boolean shouldOverrideUrlLoading(WebView view, String url) {
           Uri uri=Uri.parse(url);
               if(uri.getScheme().equals("m")&
    &
uri.getHost().equals("my.COM")){
                   String arg0=uri.getQueryParameter("arg0");
                   String arg1=uri.getQueryParameter("arg1");
                         }
else{
                   view.loadUrl(url);
           }
           return true;
   }
 }
    );

1、在html中设置链接

href=”[scheme]://[host]/[path]?[query]”

scheme可以自己在app内部设置成任意的,把android和ios的设置成一样的

2、若本地应用存在,直接打开app;若不存在,计时一段时间跳到appStore
需要判断ios还是android平台下的浏览器,需要判断微信浏览器

 var openApp = function () {
         var btnOpenApp = document.getElementById(open-app);
     btnOpenApp.onclick = function () {
         //打开本地应用函数         var open=function(url){
                 var timeout;
                      function try_to_open_app() {
                     timeout = setTimeout(function(){
                         window.location.href=url;
                     console.log(22)                        }
    , 10);
                 }
                     try_to_open_app();
         }
           if (/android/i.test(navigator.userAgent)) {
                 //alert(This is Android'browser.);
//这是Android平台下浏览器             if (/MicroMessenger/i.test(navigator.userAgent)) {
                     alert(This is MicroMessenger browser,请使用本地浏览器打开);
//这是微信平台下浏览器             }
             else {
                     open(andorid应用市场url);
             }
         }
           if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                 //alert(This is iOS'browser.);
//这是iOS平台下浏览器             if (/MicroMessenger/i.test(navigator.userAgent)) {
                     alert(微信内置浏览器不支持打开本地应用,请点击右上角使用本地浏览器打开);
//这是微信平台下浏览器             }
             else {
                     open(ios应用市场url);
             }
         }
     }
    ;
 }
       

  Android配置

 activity android:name=".ui.UploadActivity" android:screenorientation="portrait">
                 intent-filter>
                     data android:scheme="http" android:host="192.168.167.33" android:port="8088" android:path="/mi-tracker-web/download.html">
                     action android:name="android.intent.action.VIEW">
                     category android:name="android.intent.category.DEFAULT">
                     category android:name="android.intent.category.BROWSABLE">
                 /category>
    /category>
    /action>
    /data>
    /intent-filter>
             /activity>
    
              Open Application
 %@ page language="java" contentType="text/html;
     charset=ISO-8859-1"     pageEncoding="ISO-8859-1"%>
      
script type="text/javascript"> window.location="market://search?q=com.singtel.travelbuddy.android"; /script>
 String str = "market://details?id=" + getPackageName();
      Intent localIntent = new Intent("android.intent.action.VIEW");
      localIntent.setData(Uri.parse(str));
      startActivity(localIntent);
    

 HTML配置示例

Open app

Open Market

Open Market Details

Android获取参数:

 Uri uri = getIntent().getData();
      String test1= uri.getQueryParameter("arg0");
      String test2= uri.getQueryParameter("arg1");
  
 webView.setWebViewClient(new WebViewClient(){
   @Override   public boolean shouldOverrideUrlLoading(WebView view, String url) {
           Uri uri=Uri.parse(url);
               if(uri.getScheme().equals("m")&
    &
uri.getHost().equals("my.com")){
                   String arg0=uri.getQueryParameter("arg0");
                   String arg1=uri.getQueryParameter("arg1");
                         }
else{
                   view.loadUrl(url);
           }
           return true;
   }
 }
    );
    

觉得可用,就经常来吧! 欢迎评论哦! html5教程,巧夺天工,精雕玉琢。小宝典献丑了!

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

ClassdivHTMLpost-format-gallerythis

若转载请注明出处: html5写链接打开ios和android本地应用
本文地址: https://pptw.com/jishu/587099.html
HTML5开发移动web应用――SAP UI5篇(6) HTML5开发移动web应用――SAP UI5篇(5)

游客 回复需填写必要信息