我用apache cordova和angularjs为android制作了一个html5应用程序。在这个应用程序中,我有一个geojson数据的地图。数据在远程服务器上,我想加入它,获取json数据并将其写入/android/data/com.domain.name目录中的文件("正常"方式)。 GET部分没问题,但文件没有写...我在USB设备(手机)中测试应用程序,我现在不知道如何记录它。您是否在我的代码中看到了什么错误或我如何记录仿真?
那是我的代码:
/* ONCLICK */
$scope.reloadMap = function() {
/* test online */
if(navigator.onLine) {
/* url */
var url = "http://www.domain.com/API/map.js";
/* download file - distant */
$http({method: 'GET', url: url}).
success(function(data, status, headers, config) {
console.log(data);
/* write file - local */
function fail(error) {
console.log(error.code);
}
function gotFileWriter(writer) {
writer.write(data);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("data/com.domain.name/data/map.js", {create: true, exclusive: false}, gotFileEntry, fail);
}
function requestFS() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
/* write function OK */
requestFS();
}).
error(function(data, status, headers, config) {
});
}
}
我为更易读的代码减少了错误处理。
我的应用程序的/android/res/xml/config.xml(在compil之后)就像
<widget id="" version="0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
<param name="onload" value="true" />
</feature>
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
</feature>
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser" />
</feature>
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>
<name></name>
<description></description>
<author></author>
<content src="index.html" />
<access origin="*" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="true" />
<preference name="Fullscreen" value="true" />
<preference name="webviewbounce" value="false" />
<preference name="SplashScreen" value="splash" />
<preference name="SplashScreenDelay" value="4500" />
<preference name="AutoHideSplashScreen" value="false" />
<preference name="AndroidPersistentFileLocation" value="Internal" />
</widget>
没有创建目录,那有什么不对?