使用PhoneGap在Windows Phone中访问文件系统

时间:2012-04-25 13:21:55

标签: windows-phone-7 jquery-mobile cordova

我是Windows Phone新手(使用PhoneGap)。当我们使用PhoneGap进行文件写入时,创建的文件存储在哪里?我还需要检索手机上的存储路径。

 document.addEventListener("deviceready",onDeviceReady,false);    
    function onDeviceReady() {
        navigator.notification.alert("Device Ready");
        window.requestFileSystem(LocalFileSystem.APPLICATION, 0, gotFS, fail);
    }
    function gotFS(fileSystem) {
        fileSystem.root.getFile("TextFile3.txt", {create: true, exclusive: false}, gotFileEntry, fail);
        navigator.notification.alert("gotFS");
    }
    function gotFileEntry(fileEntry) {
        fileEntry.createWriter(gotFileWriter, fail);
        navigator.notification.alert("gotFileEntry");
    }
    function gotFileWriter(writer) {
        navigator.notification.alert("gotFileWriter");
        writer.onwriteend = function (evt) {
            console.log("contents of file now 'some sample text'");
            writer.truncate(11);
            writer.onwriteend = function (evt) {
                console.log("contents of file now 'some sample'");
                writer.seek(4);
                writer.write(" different text");
                writer.onwriteend = function (evt) {
                    console.log("contents of file now 'some different text'");
                    navigator.notification.alert("gotFileWriterEnd");
                }
            };
        };
        writer.write("some sample text");

    }
    function fail(error) {
        console.log(error.code);
    }

3 个答案:

答案 0 :(得分:3)

我不相信任何Windows Phone 7设备都可以访问SD卡,所以这是不可能的。

答案 1 :(得分:3)

没有设备可以直接访问SD卡,用于保存/加载持久数据的机制来自IsolatedStorage API。

您可以在此处找到详细说明:MSDN - Isolated Storage

有关示例,请参阅Jeff Blankenburg在31天Windows Phone系列中的帖子,它简要概述了一般概念,并提供了实施的代码示例。 :31 Days of Windows Phone - Isolated Storage.

答案 2 :(得分:0)

在我看来,你可能会使用其中一个PhoneGap Storage APIs。最有可能localStorage,文档声明“提供了W3C存储接口的接口”,并表明它在Windows Phone 7上受支持。

现在这并不是说它会保存到某些特定的“SD卡”(我的手机甚至没有),但我认为它会保存到隔离存储。

相关问题