【发布时间】:2016-06-05 15:49:00
【问题描述】:
我正在开发一个 Onsen/Cordova 移动应用程序,使用 Monaca 进行开发,并使用 Android 手机进行测试,该应用程序可以将照片附加到应用程序的输出中。我有这段代码可以拍照并将其复制到cordova.file.dataDirectory:
navigator.camera.getPicture(
function(imgUri) { // Success callback
// Get FileEntry object for the new photo
window.resolveLocalFileSystemURL(
imgUri,
function(fileEntry){
alert('Success - Before: ' + JSON.stringify(fileEntry));
newFileName = fileEntry.name;
window.resolveLocalFileSystemURL(cordova.file.dataDirectory,
function(dirEntry) {
// move the file to a new directory and rename it
fileEntry.moveTo(dirEntry, newFileName, function success() {
alert('Copy operation successful - After moving: ' + JSON.stringify(fileEntry)
+ '\nURL: ' + fileEntry.toURL());
$scope.photos.unshift(fileEntry.toURL());
$scope.$apply();
},
function failure(){
alert('Failed to move file.');
});
},
function failure(){
alert('Failed to get local FS for data directory.');
});
},
function failure(){
alert('Failed to get local FS for new image.');
});
},
function() { // Error callback
// We end up here if the photo selection/shoot is cancelled. So we do nothing.
return;
},
opts // Options
);
不幸的是,尽管触发了所有成功回调,但警报显示照片在移动前后的相同路径 - file://storage/emulated/0/Android/data/ mobi.monaca.debugger/cache/ - 而 cordova.file.dataDirectory 的路径是 file:///data/user/0/mobi.monaca.debugger.files/ 。
这段代码有什么不正确的地方?
【问题讨论】:
标签: cordova cordova-plugins onsen-ui monaca