Phonegap windows 8 App, with camera functionality, navigate.camera.getPicture() call back function is never called when deployed

StackOverflow https://stackoverflow.com/questions/20235310

Question

We have made a Win8 app using phonegap. The application also has a reference to a Windows runtime component used to perform some asyc task. The application has a camera feature, where in the camera is invoked, picture taken and then the picture is displayed on the screen in the success call back function. Everything works perfectly when running directly from visual studio express. The problem arises when we create a package of the application and deploy it using either metro sideloader or powershell. The camera success callback function is never called. The code for calling the camera is something like this:

    CameraService = function() {
        var that = {};

        that.invokecamera = function(callback) {
            try {
                GLOBALS.callback = callback;
                if (GLOBALS.Ready) {
                    navigator.camera.getPicture(that.onSuccess, GLOBALS.ThrowException, {
                        quality : 50,
                        saveToPhotoAlbum : true,
                        destinationType : Camera.DestinationType.FILE_URI
                    });
                }
            } catch (err) {
                alert(err);
            } finally {
            }
        }
        that.onSuccess=function(imageURI) {
        GLOBALS.ImagePath = imageURI;
        GLOBALS.callback(imageURI);
    }
        return that;
    }
Was it helpful?

Solution

Ok, So i figured out the issue mentioned here:

issue with installed app

To fix this i, as mentioned in the link replaced

Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {

With

var storageFolder = Windows.Storage.ApplicationData.current.localFolder;

In the cordova.js file. I am using cordova 2.4.0.

A more elaborated exmple

Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
                                        storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
                                            file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
                                                Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
                                                    var _imageUrl = URL.createObjectURL(file);
                                                    successCallback(_imageUrl);
                                                }, function () { errorCallback("Resize picture error."); });
                                            }, function () { errorCallback("Resize picture error."); });
                                        }, function () { errorCallback("Resize picture error."); });
                                    });

Becomes

var storageFolder = Windows.Storage.ApplicationData.current.localFolder;                                    
storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
                                            file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
                                                Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
                                                    var _imageUrl = URL.createObjectURL(file);
                                                    successCallback(_imageUrl);
                                                }, function () { errorCallback("Resize picture error."); });
                                            }, function () { errorCallback("Resize picture error."); });
                                        }, function () { errorCallback("Resize picture error."); });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top