我正在尝试在我的安卓设备(cordova 6.0.0 和 Ionic 1.7.14)中创建一个简单的文本文件,但每次它打印错误对象时,都不会创建文件。我用三星/华为和HTC设备对此进行了测试,但结果是一样的。应用程序.js和索引.js如下所示,并请求任何帮助。
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic','ngCordova'])
.controller('MyCtrl', function($scope, $cordovaFile) {
//----------------------------create file---------------------
document.addEventListener('deviceready', function () {
$cordovaFile.createFile("cordova.file.dataDirectory", "xcendant.txt", false)
.then(function (success) {
// success
alert(success);
alert("success!");
// console.log("Elaa");
}, function (error) {
// error
alert(error);
alert("fail");
});
})
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter" ng-controller="MyCtrl">
</body>
</html>
@ajantha,我不熟悉离子框架。但是,如果您在Android 6.0中使用Cordova文件插件,则插件本身存在权限问题,导致文件夹创建失败。此问题在 Apache 问题跟踪器中仍然处于打开状态,并且正在进行中,将很快发送相同的链接。
更新:此问题已在 Cordova 文件插件版本 4.2.0 中修复。Apache 问题跟踪器参考链接 https://issues.apache.org/jira/browse/CB-10798