簡體   English   中英

使用PhoneGap在Windows Phone中訪問文件系統

[英]File System access in Windows Phone using PhoneGap

我是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);
    }

我不相信任何Windows Phone 7設備都可以訪問SD卡,所以這是不可能的。

沒有設備可以直接訪問SD卡,用於保存/加載持久數據的機制是通過IsolatedStorage API。

您可以在此處找到詳細說明: MSDN - 隔離存儲

有關示例,請參閱Jeff Blankenburg在31天Windows Phone系列中的帖子,它簡要概述了一般概念,並提供了實現的代碼示例。 31天的Windows Phone - 隔離存儲。

在我看來,你可能會使用一個PhoneGap存儲API 很可能是localStorage ,文檔聲明“提供W3C存儲接口的接口”,並表明它在Windows Phone 7上受支持。

現在這並不是說它會保存到一些特定的“SD卡”(我的手機甚至沒有),但我認為它將保存到隔離存儲。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM