目录未创建,但代码 运行 在 Phonegap 中成功
Directory is not creating but code is running successfully in Phonegap
目录不是在 sd 卡中创建的,但下面的代码在我的 android 手机上运行成功 & 当我打开所需的位置时,文件夹不存在,我也浏览了之前的帖子,但没有解决我的 issue.I 也申请了所有权限,但它没有 works.Please 帮助我解决这个问题并提前感谢。
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);
}
您提到了这个位置。
var myFolderApp = "Android/data/com.acme.assetPlus/files/neeraj";
但是你没有提到内部存储(应用程序存储)或外部存储
默认情况下,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" />
目录不是在 sd 卡中创建的,但下面的代码在我的 android 手机上运行成功 & 当我打开所需的位置时,文件夹不存在,我也浏览了之前的帖子,但没有解决我的 issue.I 也申请了所有权限,但它没有 works.Please 帮助我解决这个问题并提前感谢。
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);
}
您提到了这个位置。
var myFolderApp = "Android/data/com.acme.assetPlus/files/neeraj"; 但是你没有提到内部存储(应用程序存储)或外部存储
默认情况下,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" />