IAM的努力,當我在電話部署和運行這個函數返回的錯誤,從網址上傳圖片到手機的本地存儲現在離子 - 打開失敗:EACCES(拒絕)
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>
但錯誤STI會不會改變? 我錯過了什麼嗎?請幫忙!
檢查我的答案,如果這可以解決您的問題,那麼標記它是正確的。 – Abbas
@Abbas我認爲你顯示的是原生android和iam在Ionic(Hybrid App)上工作的代碼。 順便說一句,我發現解決方案,直接給予權限。 – ArsalanK
是的我不知道離子框架,我看到EACCESS併發布了答案,我的不好。我將刪除它。 – Abbas