Is there a way with the camera plugin that when calling navigator.camera.getPicture(success, fail, options);
the user is prompted to choose the camera or photolibrary? Or do I have to implement this myself with something like the “action sheet” plugin ?
You have to do it with the action sheet I’m afraid and just switch the config up based on the action selected. This library will make things slightly easier and more uniform http://ngcordova.com/docs/plugins/camera
I tried to do this by incorporating the action sheet into the Camera factory, but cant seem to get it to work. Has anyone else got this to work?
UPDATED: Got this to work by creating a function for the actionsheet with a callback.
.factory('Camera', ['$q', '$ionicActionSheet', function ($q, $ionicActionSheet) {
return {
getPicture: function () {
var q = $q.defer(),
options = {quality : 50, destinationType : 1, sourceType : 1, correctOrientation : true};
function showActionSheet (callback) {
$ionicActionSheet.show({
titleText: '<font color="black">Choose Picture Source</font>',
buttons: [
{ text: '<i class="icon ion-camera"></i>Camera' },
{ text: '<i class="icon ion-images"></i>Photo Gallery' }
],
cancelText: 'Cancel',
cancel: function() {
console.log('CAMERA ACTIONSHEET CANCELLED');
q.reject('Cancelled');
},
buttonClicked: function(index) {
console.log('CAMERA ACTIONSHEET BUTTON CLICKED', index);
if (index === 0) {
options = {quality : 50, destinationType : 1, sourceType : 1, correctOrientation : true};
} else if (index === 1) {
options = {quality : 50, destinationType : 1, sourceType : 0, correctOrientation : true};
}
if (callback && typeof(callback) === "function") {
callback();
}
return true;
}
});
}
showActionSheet(function (){
navigator.camera.getPicture(function (result) {
q.resolve(result);
}, function (err) {
q.reject(err);
}, options);
});
return q.promise;
}
};
}])
.controller('myFrmCtrl', function ($scope, Camera) {
$scope.getPhoto = function () {
Camera.getPicture().then(function (imageURI) {
console.log(imageURI);
$scope.f1_Photo = imageURI;
}, function (err) {
console.err(err);
});
};
})