2016-09-27 50 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将它们复制到电脑上。

相关问题