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

3

我是一个新手,正在使用PhoneGap开发Windows Phone应用。当我们使用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个回答

3

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


嗨,保罗。实际上我正在尝试使用以上代码,但我无法找出它是否被创建,文件路径也不清楚。谢谢。 - Akil Pandu
1
请按照以下步骤操作,然后将其移植到您可以从PhoneGap项目中调用的方法中:http://www.windowsphonegeek.com/tips/all-about-wp7-isolated-storage--intro-to-isolated-storage - Paul Diston
谢谢Paul,实际上我想看到在我们的手机模拟器中创建的文件/文件夹的位置。我该如何查看物理文件?谢谢。 - Akil Pandu

3
没有任何设备可以直接访问SD卡,用于保存/加载持久数据的机制是通过IsolatedStorage API。你可以在这里找到详细的解释: MSDN - Isolated Storage
例如,Jeff Blankenburg在Windows Phone系列的31天帖子中提供了一个示例,它对总体概念进行了简要概述,并提供了实现的代码示例:31 Days of Windows Phone - Isolated Storage.

谢谢Jamie, 实际上我正在使用Phonegap进行Windows Mobile开发。你能否给出存储路径或在Windows Mobile SD卡中保存文件的简单示例? 谢谢 - Akil Pandu
1
@AkilPandu 你可能不理解Jamie的正确答案。手机绝对没有任何访问SD卡的能力。PhoneGap是在Windows Phone SDK之上运行的平台,这意味着它也不能访问SD卡。再次强调:这是不可能完成的。此外(这更多是个人意见),请尽量使用本地方式开发Windows Phone应用程序。使用PhoneGap在Windows Phone上提供良好的UI存在一些问题。当然,您可以为三个平台快速开发应用程序,但代价(过高)是质量。 - Paul Hazen
谢谢,但我需要将一些文件存储在Windows手机存储中。你能给个例子吗? - Akil Pandu
为了首先创建文件,您应该知道路径...?你想做什么? - Jamie Keeling
实际上我之前发布的代码已经可以正常工作了,但是我找不到文件创建的位置。我正在使用 PhoneGap(Windows Mobile)进行示例演示!因此,我需要文件路径。 - Akil Pandu
显示剩余3条评论

0

在我看来,您可能会使用其中一个PhoneGap存储API。最有可能的是{{link2:localStorage}},文档中指出它“提供了一个W3C存储接口”的接口,并表明它支持Windows Phone 7。

现在这并不意味着它会保存到某个特定的“SD卡”上(我的手机甚至没有),但我认为它将保存到隔离存储中。


谢谢,实际上我想在我们的Windows Mobile(PhoneGap)中创建和读取一个文本文件,您能否给我提供示例代码。 - Akil Pandu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接