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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM