gpt4 book ai didi

android - ionic - 打开失败 : EACCES (Permission denied)

转载 作者:行者123 更新时间:2023-11-30 00:59:37 25 4
gpt4 key购买 nike

我正在尝试将图片从 URL 上传到手机的本地存储

 appController.controller('TestCtrl',['$scope','$cordovaFileTransfer', function($scope,$cordovaFileTransfer){

$scope.Download = function () {
ionic.Platform.ready(function(){
var url = "http://3.bp.blogspot.com/-XchURXRz-5c/U5ApPOrPM9I/AAAAAAAADoo/YZEj4qeSlqo/s1600/Final-Fantasy-XV-Noctis-Red-Eyes.png";
var filename = url.split("/").pop();
var targetPath = cordova.file.externalRootDirectory + 'Pictures/' + filename;
console.log(targetPath);

$cordovaFileTransfer.download(url, targetPath, {}, true).then(function (result) {
$scope.hasil = 'Save file on '+targetPath+' success!';
$scope.mywallpaper=targetPath;
}, function (error) {
console.log(error);
$scope.hasil = 'Error Download file'+error;
}, function (progress) {
$scope.downloadProgress = (progress.loaded / progress.total) * 100;
});
});
}
}]);

现在,当我在手机中部署并运行此函数时,它返回错误,通过调试我发现:打开失败:EACCES(权限被拒绝)

我还添加了对 AndroidManifest.xml 的权限

<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.foodhubb" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>

但是错误还是没有改变?我错过了什么?请帮忙!

最佳答案

你是如何解决这个问题的?

目前 CordovaFileTransfer 不支持这些权限 ( There is currently a PR open for it on GitHub )

我同时使用 $cordovaFile(它实现了这些权限)解决了我的问题:

//HACK - $cordovaFileTransfer doesn't support permissions so we get permission here with $cordovaFile
$cordovaFile.createFile(externalAppPath, "permissions.dat", true)
.then(function (success) {
$cordovaFile.removeFile(externalAppPath, "permissions.dat")
.then(function (success) {
// success
downloadPromise = $cordovaFileTransfer.download(url, targetPath, options, trustHosts);
downloadPromise.then(function (result) {
...
...
}, function (error) {
// error couldn't delete tmp file
});
}, function (error) {
$scope.modal.hide();
$ionicPopup.alert({
title: "Permission denied",
template: "The file could not be downloaded, permission was denied.",
cssClass: 'error-popup'
});
return;
});

关于android - ionic - 打开失败 : EACCES (Permission denied),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39613864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com