$cordovaFileOpener2



$cordovaFileOpener2是cordova打开文件插件,这个插件将打开你的设备文件系统的文件,如apk应用程序文件,pdf文件等,还可以检测是是否安装了 一个应用。



cordova plugin add https://github.com/pwlin/cordova-plugin-file-opener2.git


打开APK安装对话框

module.controller('MyCtrl', function($scope, $cordovaFileOpener2) {

  $cordovaFileOpener2.open(
    '/sdcard/Download/gmail.apk',
    'application/vnd.android.package-archive'
  ).then(function() {
      // Success!
  }, function(err) {
      // An error occurred. Show a message to the user
  });

});

用默认的PDF阅读器和可选的回调对象打开PDF文档

module.controller('MyCtrl', function($scope, $cordovaFileOpener2) {

  $cordovaFileOpener2.open(
    '/sdcard/Download/starwars.pdf',
    'application/pdf'
  ).then(function() {
      // file opened successfully
  }, function(err) {
      // An error occurred. Show a message to the user
  });

});

卸载一个APP,通过appid

1. module.controller(‘MyCtrl’, function($scope, $cordovaFileOpener2) {
2.
3.$cordovaFileOpener2.uninstall(‘com.zynga.FarmVille2CountryEscape’).then(function() { // Uninstall intent activity started. }, function(err) { // An error occurred. Show a message to the user });
4.
5.});

检查一个应用程序是否已经安装。

module.controller('MyCtrl', function($scope, $cordovaFileOpener2) {
		
		  $cordovaFileOpener2.appIsInstalled('com.adobe.reader').then(function(res) {
		      if (res.status === 0) {
		          // Adobe Reader is not installed.
		      } else {
		          // Adobe Reader is installed.
		      }
		  });
		
		});