目录未创建,但代码在Phonegap中成功运行

时间:2016-01-04 07:51:45

标签: android file cordova file-transfer

目录不是在SD卡中创建的,但是下面的代码在我的android mobile&当我打开所需的位置,然后没有文件夹存在时,我也经历了早期的帖子,但它并没有解决我的问题。我还申请了所有权限,但它没有起作用。请帮我解决这个问题&提前完成。

 function capturePhoto(){  
// Take picture using device camera and retrieve image as base 64-encoded string
navigator.camera.getPicture( onPhotoDataSuccess, onFail, {quality:100,destinationType:Camera.DestinationType.FILE_URI});
}
var imageForCategory="";
function onPhotoDataSuccess(imageData) { 

  // Uncomment to view the base64-encoded image data
   alert("imageData "+imageData);  
  // Get image handle

  var smallImage = document.getElementById('smallImage');
  // Unhide image elements
  smallImage.style.display = 'block';
  // Show the captured photo
  // The in-line CSS rules are used to resize the image


  smallImage.src = imageData;
  imageForCategory=smallImage.src;


}
function onFail(message) {
  alert('Failed because: ' + message);
}
function getPhoto(source) { 
  // Retrieve image file location from specified source
  navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100,destinationType: destinationType.FILE_URI,
  sourceType: source });
}

function onPhotoURISuccess(imageURI) { 
  // Uncomment to view the image file URI
   alert(imageURI);

  // Get image handle
  //
  var largeImage = document.getElementById('largeImage');

  // Unhide image elements
  //
  largeImage.style.display = 'block';

  // Show the captured photo
  // The in-line CSS rules are used to resize the image
  //
  largeImage.src = imageURI;
  imageForCategory=largeImage.src;
 // i++;    // for image data array to get array of images to be uploaded
}

function saveAsset()
{  

if(imageForCategory!=""){  alert("imageForCategory : "+imageForCategory);
     window.resolveLocalFileSystemURL(imageForCategory,resolveOnSuccess,resOnError); 
 }
 else{ 
    db = window.openDatabase("finnAssistDB", "1.0", "finnAssist", 200000);
        db.transaction(function(tx){
            saveAssetSQL(tx,"");
        }, transaction_error);

 }

}
 function resOnError(error) {
alert('Error at resOnError :'+error.code+' ,message :'+error.message);
}
function resolveOnSuccess(fileSystem)
{  
 alert("fileSystem name : "+fileSystem.name);

var d = new Date();
var n = d.getTime();
var newFileName = n + ".jpg";

var myFolderApp = "Android/data/com.acme.assetPlus/files/neeraj";
var newFile=myFolderApp+"/"+newFileName;

window.requestFileSystem(LocalFileSystem.PERSISTENT,0, function(fileSys) { 
alert("fileSys name "+fileSys.name); 
alert("fileSys.root.fullPath "+fileSys.root.toURL()); // displays "path of directory" 
alert("fileSys getParent : "+fileSys.root.getParent); // displays the parent

fileSys.root.getDirectory(myFolderApp,{create:true, exclusive: false},
                function(directory)
                {       alert("directory name : "+directory.name);   

               /* fileSystem.copyTo(directory, newFileName,function(fileSystem)*/
                fileSystem.moveTo(directory,newFileName,function(fileSystem)
                        { alert("fileSystem "+fileSystem);
                        db = window.openDatabase("finnAssistDB", "1.0", "finnAssist", 2000000);
                        db.transaction(function(tx){
                            saveAssetSQL(tx,newFile);
                        }, transaction_error);
                    }, resOnError);
                },resOnError); 
                },resOnError); 

}

1 个答案:

答案 0 :(得分:1)

您已提及此位置。

var myFolderApp =“Android / data / com.acme.assetPlus / files / neeraj”; 但您没有提到内部存储(App Storage)或外部存储

默认情况下,Android会考虑内部存储。

根据您的代码,图片文件夹是在data/data/yourpackagename/Android/data/com.acme.assetPlus/files/neeraj

中创建的

要保存在外部存储中,请在config.xml中添加此行

<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />

另外在AndroidManifest.xml中

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