Skip to content

juanfc/cordova-open

 
 

Repository files navigation

cordova-open

Build Status Code Climate

Forked https://github.com/disusered/cordova-open

I implemented file share to:

Open & Share audio, video, images and more with applications installed on the user's device.

Install

$git clone https://github.com/juanfc/cordova-open.git
$cordova plugin add  cordova-open --link

or

$cordova plugin add https://github.com/juanfc/cordova-open.git

Usage open

var open = cordova.plugins.disusered.open;

function success() {
  console.log('Success');
}

function error(code) {
  if (code === 1) {
    console.log('No file handler found');
  } else {
    console.log('Undefined error');
  }
}

function progress(progressEvent) {
  if (progressEvent.lengthComputable) {
    var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
    // update UI with status, for example:
    // statusDom.innerHTML = perc + "% loaded...";
  } else {
    // download does not offer a length... just show dots
    /*
       if(statusDom.innerHTML == "") {
       statusDom.innerHTML = "Loading";
       } else {
       statusDom.innerHTML += ".";
       }
     */
  }
};

open('file:/storage/sdcard/DCIM/Camera/1404177327783.jpg', success, error, progress);

Usage shareFile

var open = cordova.plugins.disusered.shareFile;

function success() {
  console.log('Success');
}

function error(code) {
  if (code === 1) {
    console.log('No file handler found');
  } else {
    console.log('Undefined error');
  }
}

function progress(progressEvent) {
  if (progressEvent.lengthComputable) {
    var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
    // update UI with status, for example:
    // statusDom.innerHTML = perc + "% loaded...";
  } else {
    // download does not offer a length... just show dots
    /*
       if(statusDom.innerHTML == "") {
       statusDom.innerHTML = "Loading";
       } else {
       statusDom.innerHTML += ".";
       }
     */
  }
};

open(cordova.file.externalCacheDirectory +fileName, success, error, progress);

API

The plugin exposes the following methods: *shareFile (Only for Android Api >=22)

cordova.plugins.disusered.open(file, success, error, progress, trustAllCertificates)
cordova.plugins.disusered.shareFile(file, success, error, progress, trustAllCertificates)

Parameters:

  • file: A string representing a URI
  • success: Optional success callback
  • error: Optional error callback
  • progress: Optional progress callback
  • trustAllCertificates: Optional, trusts any certificate when the connection is done over HTTPS.

Events:

  • pause: Opening files emits Cordova's pause event (Android only)
  • resume: Closing the file emits Cordova's resume event
  • open.success: File is found and can be opened
  • open.error: File not found, or no file handler is installed

License

MIT © Carlos Rosquillas

About

Open audio, video, images and more with applications installed on the user's device

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 42.7%
  • Java 33.6%
  • Objective-C 19.5%
  • Shell 4.2%