![](/img/trans.png)
[英]cordova navigator.camera.getPicture not working in android
[英]Cordova 3.4.0 navigator.camera.getPicture does not callback onSuccess or onFail for Android 4.3
我使用Cordova 3.4和Camera Plugin( https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md )
我打電話的時候
navigator.camera.getPicture(onSuccess, onFail, {
quality: 75,
destinationType: window.Camera.DestinationType.FILE_URI,
sourceType: window.Camera.PictureSourceType.CAMERA,
//allowEdit: true,
//cameraDirection: window.Camera.Direction.FRONT,
//encodingType: window.Camera.EncodingType.JPEG,
//targetWidth: 100,
//targetHeight: 100,
//popoverOptions: window.CameraPopoverOptions,
saveToPhotoAlbum: true
});
function onSuccess(imageData) {
alert(imageData);
}
function onFail(message) {
alert('Failed because: ' + message);
}
此代碼適用於Windows Phone 8.1,但不適用於Android 4.3(Jelly Bean)。 當我在eclipse中進入代碼時,我可以看到它在android臨時目錄下成功保存了照片,但是在完成時沒有調用JavaScript成功或失敗事件,這就是我無法在android上獲取圖像的原因。
我都試過Galaxy Note 2真實設備和模擬器,但兩者都沒有調用onSuccess。
此問題是否存在任何已知問題或解決方法?
試試這個選項:
destinationType: navigator.camera.DestinationType.FILE_URI
sourceType: source
mediaType: media
如果這不起作用,請讓我建議這些選項。 他們的工作部署在4.2.2(Jellybean)android和4.4.2(Kitkat)上。
navigator.camera.getPicture(this.onPhotoDataSuccess, this.onFail, {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA
});
//閱讀並附加DOM
onPhotoDataSuccess(imageData) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
}
這將返回base64編碼的圖像。
如果它可以幫助任何人,我有同樣的問題。 事實證明,我在應用程序的Cordova“暫停”事件中調用了“navigator.camera.cleanup()”(因此當應用程序被發送到后台時它會清理資源)。 這里的問題是相機將應用程序發送到后台,所以顯然調用清理是破壞事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.