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

  • 相关阅读:
    cocos2dx3.0戳青蛙游戏(打地鼠)
    深入理解Tomcat系列之五:Context容器和Wrapper容器
    linux下拷贝隐藏文件
    8.8.1 运行计划
    UVALive
    堆排序实现
    C语言中的signal函数
    uboot和内核分区的改动
    Android缩放动画
    .Net 自定义应用程序配置
  • 原文地址:https://www.cnblogs.com/nullman/p/5869082.html
Copyright © 2011-2022 走看看