2016-09-27 94 views
2

我深化發展映射目的的應用程序將數據寫入到它.. 我創建KML和JSON字符串,我需要將它們存儲在文件中的手機內存,這樣做,我用了以下代碼:創建一個文件,並用離子

var fileObject; 

    document.addEventListener("deviceready", onDeviceReady, true); 

    function onDeviceReady() 
    { 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,onFileSystemSuccess, fail); 
    } 

    function onFileSystemSuccess(fileSystem) { 
    fileSystem.root.getFile("readme.txt",{create: true, exclusive: false},gotFileEntry, fail); 
    } 

    function gotFileEntry(fileEntry) { 
    fileObject = fileEntry; 
    $('#saveFile_btn').on('click', function() { 
     saveFileContent(); 
    }); 
    } 

    function saveFileContent() { 
    fileObject.createWriter(gotFileWriter, fail); 
    } 

    function gotFileWriter(writer) { 
    var myText = document.getElementById('my_text').value; 
    writer.write(myText); 
    writer.onwriteend = function(evt) { 
     $('#message').html('<p>File contents have been written.<br /><strong>File path:</strong> ' + fileObject.fullPath + '</p>'); 
     var reader = new FileReader(); 
     reader.readAsText(fileObject); 
     reader.onload = function(evt) { 
     $('#contents').html('<strong>File contents:</strong> <br />'+ evt.target.result); 
     }; 
    }; 
    } 

    function fail(error){ 
    alert(error.code); 
    } 

結果不是錯誤,但我在內存中找不到該文件。

enter image description here

回答

0

賓果 只有root訪問權限可以看到這些文件。這是爲了防止應用程序隨意刪除內容的人員破壞應用程序。

我用Root Explorer來訪問android設備中的文件,然後adb pull將它們複製到電腦上。