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);
      });
    }

  • 相关阅读:
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    When:什么时候做集成测试
  • 原文地址:https://www.cnblogs.com/nullman/p/5869082.html
Copyright © 2011-2022 走看看