ng-cordova createFile () 方法(在文件 API 中)在 android 设备中不起作用
ng-cordova createFile () method (In file API) is not working in android devices
我正在尝试在我的 android 设备(cordova 6.0.0 和 Ionic 1.7.14)中创建一个简单的文本文件,但每次它打印错误对象时都不会创建文件。我用三星/华为和 HTC 设备测试了这个,但结果是一样的。 app.js 和 index.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 文件插件,则插件本身存在权限问题,导致文件夹失败 creation.This 问题在 Apache 问题跟踪器和 progress.will 中仍然存在尽快发送 link。
更新:该问题已在 Cordova 文件插件版本 4.2.0 中修复。 Apache 问题跟踪器参考 link 是 https://issues.apache.org/jira/browse/CB-10798
我正在尝试在我的 android 设备(cordova 6.0.0 和 Ionic 1.7.14)中创建一个简单的文本文件,但每次它打印错误对象时都不会创建文件。我用三星/华为和 HTC 设备测试了这个,但结果是一样的。 app.js 和 index.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 文件插件,则插件本身存在权限问题,导致文件夹失败 creation.This 问题在 Apache 问题跟踪器和 progress.will 中仍然存在尽快发送 link。
更新:该问题已在 Cordova 文件插件版本 4.2.0 中修复。 Apache 问题跟踪器参考 link 是 https://issues.apache.org/jira/browse/CB-10798