zoukankan      html  css  js  c++  java
  • ionic实现手机检测app是否安装,未安装则下载安装包,已安装则打开app(未实现iOS平台)

    插件需求(上cordova官网下载):

    com.lampa.startapp

    cordova-plugin-appavailability

    cordova-plugin-inappbrowser

    代码:

    对于iOS和android平台的判断

    var u = navigator.userAgent;
    var ua = navigator.userAgent.toLowerCase();
    if(!!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/)){//如果是ios
      //do something
    }
    if (ua.match(/Android/i) == "android") {//如果是android
      // do something
    }

    检测手机内是否有此安装的app

    appAvailability.check(
      'xxxx', // URI Scheme 这里是app的包名,可以搜一些包名查看器,一般都是com.xxx.xxxx格式的
      function () { // Success callback
        //成功回调函数,可以执行开始app的方法

        $scope.startApp();
      },
      function () { // Error callback
        //失败的回调函数
      }
    );

    开始app的方法

    $scope.startapp = function(){
      var sApp = startApp.set({ /* params */
        "action":"ACTION_MAIN",
        "category":"CATEGORY_DEFAULT",
        "type":"text/css",
        "package":"com.android.GoBallistic",
        "uri":"file://data/index.html",
        "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"],
        // "component": ["com.android.GoBallistic","com.android.GoBallistic.Activity"],
        "intentstart":"startActivity",
    }, { /* extras */
        "EXTRA_STREAM":"extraValue1",
        "extraKey2":"extraValue2"
    });
      sApp.start(function() { /* success */
        console.log("OK");
      }, function(error) { /* fail */
        console.log(error);
      });
    }

  • 相关阅读:
    保持URL不变和数字验证
    centOS ftp key?
    本地环境测试二级域名
    linux 解决You don't have permission to access 问题
    php smarty section loop
    php header Cannot modify header information headers already sent by ... 解决办法
    linux部分命令
    Linux 里面的文件操作权限说明
    用IT网络和安全专业人士视角来裁剪云的定义
    SQL Server 2008 R2炫酷报表"智"作有方
  • 原文地址:https://www.cnblogs.com/nullman/p/5869082.html
Copyright © 2011-2022 走看看