我正在使用cordova相机插件(我从他们的github上获取了最新版本)并且它在iOS上运行良好,但它在Android(模拟器)上无效。我正在使用Ionic 1.它确实打开了相机和所有这些东西,但在我按下" Save"之后,没有其他事情发生。 我知道我不能使用相机,所以我从相机胶卷中选择照片。但似乎从未调用过getPicture方法
以下是代码:
var index = btnIndex;
var source = -1;
if(index == 1){
//choose from album
if(ionic.Platform.isIOS()){
source = Camera.PictureSourceType.PHOTOLIBRARY;
}else{
source = Camera.PictureSourceType.SAVEDPHOTOALBUM;
}
}else if(index == 2){
//take new picture
source = Camera.PictureSourceType.CAMERA;
}
if(source > -1) {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: source,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 320,
targetHeight: 320,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function (imageURI) {
console.log("send file to server");
var imgTag = document.getElementById("myImage");
alert("imageURI: " + imageURI);
var url = SERVER.url + "upload.php";
var opt = new FileUploadOptions();
opt.fileName = $scope.currentUser.clientID + ".jpg";
$cordovaFileTransfer.upload(url, imageURI, opt)
.then(function(result) {
imgTag.src = $scope.currentUser.clientID + ".jpg?" + new Date().getTime(); //time is used to refresh the image
}, function(err) {
alert("Ein Fehler ist aufgetreten: " + JSON.stringify(err));
}, function (progress) {
console.log("progress: " + progress);
});
}), function(error){
alert("ERROR: " + JSON.stringify(error));
};
$cordovaCamera.cleanup();
}