cordova-plugin-android-permissions
cordova-plugin-android-permissions copied to clipboard
Passing argument to the success callback
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?
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();