cordova-plugin-android-permissions icon indicating copy to clipboard operation
cordova-plugin-android-permissions copied to clipboard

Passing argument to the success callback

Open wwhyte opened this issue 8 years ago • 1 comments

Thanks for putting this extension together!

I want to use it in conjunction with the cordova-plugin-save-image plugin to write a photo that I take in my app to a gallery. The natural way to do this seems to be

  pictureTakenHandler(function(photoData){
    glPhotoData = photoData;
    permissions.hasPermission(permissions.WRITE_EXTERNAL_STORAGE, storageAllowedHandler, null);
  });

and then use storageAllowedHandler to write the photo. But it seems that the prototype to the success callback takes only one argument, the status value arising from permissions.hasPermission. How can I pass photoData to the success callback? Or is there a different approach you recommend?

wwhyte avatar Feb 03 '17 11:02 wwhyte

Use closures, for example using classes:

var app = {

    takePhoto: function (){ 
        // ... 
    },

    glPhotoData: null,
    
    pictureTakenHandler: function (photo) {
        app.glPhotoData = photo;
        permissions.hasPermission( permissions.WRITE_EXTERNAL_STORAGE, app.storageAllowedHandler, null);
    },

    storageAllowedHandler: function(status) {

        if ( status.hasPermission ) {
            app.save(app.glPhotoData); // implements your own save method
        }
    }
};
app.takePhoto();

pwqw avatar Feb 26 '17 21:02 pwqw