gpt4 book ai didi

java - 移动/复制捕获的图像phonegap android中的问题

转载 作者:行者123 更新时间:2023-11-29 08:52:19 25 4
gpt4 key购买 nike

Phonegap 版本:3.3

安卓版本:4.0.4

我正在分享我得到的文件 uris 以供引用。

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();
}
}
}

最佳答案

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

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

关于java - 移动/复制捕获的图像phonegap android中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22164672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com