移动/复制拍摄的图像phonegap android的问题



Phonegap版本:3.3

安卓版本:4.0.4

我正在分享我得到的文件uri以供参考

FILE_URI=content://media/external/images/media/11679

FILE_URI=file:///mnt/sdcard/Android/data/com.allplugins/cache/1393913804418.jpg

我在将捕获的图像移动到SD卡时出错。我也尝试过window.resolveLocalFileSystemURLwindow.resolveLocalFileSystemURI,但都不适用。

当我试图将相机拍摄的图像移动到sd卡时,我得到了错误代码"1"。

错误日志

> 03-04 12:02:54.482: I/Web Console(27289): Info : got file entry
> ![object Object] at file:///android_asset/www/js/me/view/demo.js:383
> 
> 03-04 12:02:54.482: W/System.err(27289):  at
> org.apache.cordova.file.FileUtils.access$8(FileUtils.java:583)
> 
> 03-04 12:02:54.482: W/System.err(27289):  at
> org.apache.cordova.file.FileUtils$21.run(FileUtils.java:407)
> 
> 03-04 12:02:54.482: W/System.err(27289):  at
> org.apache.cordova.file.FileUtils$24.run(FileUtils.java:473)
> 
> 03-04 12:02:54.482: W/System.err(27289):  at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
> 
> 03-04 12:02:54.482: W/System.err(27289):  at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
> 
> 03-04 12:02:54.482: W/System.err(27289):  at
> java.lang.Thread.run(Thread.java:856)
> 
> 03-04 12:02:54.483: D/IPCThreadState(27289): [DN #5]
> BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x1b36d10
> 
> 03-04 12:02:54.574: D/CordovaLog(27289):
> file:///android_asset/www/js/me/view/demo.js: Line 384 : Error : file
> move !{"code":1}
> 
> 03-04 12:02:54.574: I/Web Console(27289): Error : file move
> !{"code":1} at file:///android_asset/www/js/me/view/demo.js:384

我的代码

function PhotoKeeper() {
var name_of_image = "";
var pictureSource,destinationType;
var selectedSourceType;
var fileSysRoot,projectImageDirectory,projectImageDirectoryName = "temp";
init();
function init(){
destinationType = window.Camera.DestinationType;
pictureSource = window.Camera.PictureSourceType;
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
0,
// got file system sucess callback
function (arg_o_filesys){
fileSysRoot = arg_o_filesys.root;
arg_o_filesys.root.getDirectory(
projectImageDirectoryName,
{
create: true,
exclusive: false
},
// got directory entry sucess callback
function(arg_o_directoryEntry) {
console.log("Info : got directory entry !");
projectImageDirectory = arg_o_directoryEntry;
},
errorPhoto
);
},
errorPhoto
);
}
function getPhotoFromLibreary(){
selectedSourceType = pictureSource.PHOTOLIBRARY;
window.navigator.camera.getPicture(
gotPhoto,
errorPhoto,
{ 
"quality": 50,
"destinationType": destinationType.FILE_URI,
"sourceType": selectedSourceType
}
);
}
function getPhotoFromCamera(){
selectedSourceType = pictureSource.CAMERA;
window.navigator.camera.getPicture(
gotPhoto,
errorPhoto,
{ 
"quality": 50,
"destinationType": destinationType.FILE_URI,
"sourceType": selectedSourceType
}
);
}
function gotPhoto(fileuri){
window.resolveLocalFileSystemURL(fileuri, gotFileEntry, errorPhoto);
}
// got fileEntry sucess callback
function gotFileEntry(arg_o_fileEntry){
console.log("Info : got file entry !"+arg_o_fileEntry);
arg_o_fileEntry.copyTo( projectImageDirectory, name_of_image , function(){ console.log("Info : file moved !") } , function(e){ console.log("Error : file move !"+e); } );
}
function errorPhoto(msg){
console.log("Error : "+JSON.stringify(msg));
}
function updateName (argname_of_image) {
if((utils.isUndefined(argname_of_image) === false) && (typeof argname_of_image == "string")){
name_of_image = argname_of_image;
}else{
name_of_image = Date.now().toString();
}
}
return{
getPhotoFromLibreary : function (name_of_image) {
updateName(name_of_image);
getPhotoFromLibreary();
},
getPhotoFromCamera : function (name_of_image) {
updateName(name_of_image);
getPhotoFromCamera();
}
}
}

确保在清单文件中添加了读取和写入外部存储的适当权限。如果没有,请将以下代码添加到您的清单文件中。

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

问题在于phonegap 3.3。我已经用phonegap 3.4测试了我的代码,它的工作原理很有魅力。

相关内容

  • 没有找到相关文章

最新更新