Javascript 使用phonegap时,window.resolveFileSystemURI()和window.requestFileSystem均不存在?

Javascript 使用phonegap时,window.resolveFileSystemURI()和window.requestFileSystem均不存在?,javascript,android,cordova,devexpress,Javascript,Android,Cordova,Devexpress,我刚开始使用Phonegap,不幸的是我遇到了一个问题。使用camera api成功捕获图像,但我也想将图片从缓存移动到android设备的选定文件夹。我浏览了整个互联网,有些人使用window.resolvefilesystemmuri,但它不存在于我的项目中 TestCamera.home = function (params) { //Callback function when the picture has been successfully taken function onPhot

我刚开始使用Phonegap,不幸的是我遇到了一个问题。使用camera api成功捕获图像,但我也想将图片从缓存移动到android设备的选定文件夹。我浏览了整个互联网,有些人使用window.resolvefilesystemmuri,但它不存在于我的项目中

TestCamera.home = function (params) {
//Callback function when the picture has been successfully taken
function onPhotoDataSuccess(imageData) {
    // Get image handle
    var smallImage = document.getElementById('smallImage');

    // Unhide image elements
    smallImage.style.display = 'block';
    smallImage.src = imageData;
    alert(imageData);
    //movePic(imageData);

}

function onPhotoURISuccess(imageURI) {
    var largeImage = $('#largeImage');
    largeImage.css('display', 'block');
    largeImage.attr('src', imageURI);
}
function getPhoto(source) {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 50,
        destinationType: TestCamera.destinationType.FILE_URI,
        sourceType: source
    });
}
function onFail(message) {
    alert('Failed because: ' + message);
}
function movePic(file) {
    window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError);
}

//Callback function when the file system uri has been resolved
function resolveOnSuccess(entry) {
    var d = new Date();
    var n = d.getTime();
    //new file name
    var newFileName = n + ".jpg";
    var myFolderApp = "EasyPacking";

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) {
        //The folder is created if doesn't exist
        fileSys.root.getDirectory(myFolderApp,
                { create: true, exclusive: false },
                function (directory) {
                    entry.moveTo(directory, newFileName, successMove, resOnError);
                },
                resOnError);
    },
resOnError);

}

//Callback function when the file has been moved successfully - inserting the complete path
function successMove(entry) {
    //I do my insert with "entry.fullPath" as for the path
    alert(entry);
}

function resOnError(error) {
    alert(error.code);
}
var viewModel = {
    capturePhoto: function (e) {
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
            quality: 50,
            destinationType: TestCamera.destinationType.FILE_URI

        });
    },
    capturePhotoEdit: function (e) {
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
            quality: 20,
            allowEdit: true,
            destinationType: TestCamera.destinationType.FILE_URI
        });
    },
    photoLibrary: function (e) {
        getPhoto(TestCamera.pictureSource.PHOTOLIBRARY);
    },
    photoAlbum: function (e) {
        getPhoto(TestCamera.pictureSource.SAVEDPHOTOALBUM);
    }
};

return viewModel;
})

!!窗口[resolveFileSystemURI()]返回true, 我是不是丢失了一个文件什么的? 任何帮助都将不胜感激:)
Daan Helsloot

我认为您应该首先在项目中添加文件插件:

phonegap local plugin add org.apache.cordova.file
phonegap local plugin add org.apache.cordova.file-transfer
顺便说一句,对于您的问题,我有另一个解决方案,您可以使用以下代码检索捕获图像的base64:

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
    destinationType: Camera.DestinationType.DATA_URL
});

然后将base64编码保存到您想要的任何目录

Hi Hazem,首先感谢您的帮助!我可以在不使用命令行工具的情况下添加这些插件吗?我已经尝试了您提供的其他解决方案,但不幸的是,没有成功:(@DaanHelsloot:尝试使用命令行工具,因为它是最好的,而且是100%安全的