From 464c37eb50467a7aed91e51aac371c8aed298811 Mon Sep 17 00:00:00 2001 From: Piotr Zalewa Date: Fri, 20 Sep 2013 19:59:05 +0200 Subject: [PATCH] getPicture via web activities --- plugin.xml | 4 ++-- src/firefoxos/camera.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/firefoxos/camera.js diff --git a/plugin.xml b/plugin.xml index 0f9ad2e..efcf471 100644 --- a/plugin.xml +++ b/plugin.xml @@ -32,8 +32,8 @@ - - + + diff --git a/src/firefoxos/camera.js b/src/firefoxos/camera.js new file mode 100644 index 0000000..270f221 --- /dev/null +++ b/src/firefoxos/camera.js @@ -0,0 +1,32 @@ + +var firefoxos = require('cordova/platform'); + +function getPicture(cameraSuccess, cameraError, cameraOptions) { + cameraError = cameraError || function(){}; + var pick = new MozActivity({ + name: "pick", + data: { + type: ["image/png", "image/jpg", "image/jpeg"] + } + }); + pick.onerror = cameraError; + pick.onsuccess = function() { + // image is returned as Blob in this.result.blob + // we need to call cameraSuccess with url or base64 encoded image + if (cameraOptions && cameraOptions.destinationType == 0) { + // TODO: base64 + return; + } + if (!cameraOptions || !cameraOptions.destinationTyoe || cameraOptions.destinationType > 0) { + // url + return cameraSuccess(window.URL.createObjectURL(this.result.blob)); + } + }; +} +var Camera = { + takePicture: getPicture, + cleanup: function(){} +}; + +firefoxos.registerPlugin('Camera', Camera); +