[英]Android: EACCES Permission denied to save a file in the ringtones folder
I`m trying to download an MP3 file from the web using a stream and save it to the ringtones folder using this method 我正在尝试使用流从Web下载MP3文件并将其保存到使用此方法的铃声文件夹中
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES)
I`ve added the required permissions: 我已经添加了所需的权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.write_external_storage"/>
When I check my app on an emulator (I currently use Andy) the app works perfectly. 当我在模拟器上检查我的应用程序(当前使用Andy)时,该应用程序可以正常运行。 When I check it on an actual device (more than one) I get no permission: /storage/sdcard0/Ringtones/MyRingtone.mp3: open failed: EACCES (Permission denied)
当我在一个实际设备(一个以上)上检查它时,我没有任何权限:/storage/sdcard0/Ringtones/MyRingtone.mp3:打开失败:EACCES(权限被拒绝)
Anyone has any idea what is missing? 任何人都知道缺少什么吗?
Here is the full method to download: 这是完整的下载方法:
protected String doInBackground(String... f_url) {
Log.d(TAG, "doInBackground.Started");
int count;
try {
mDownloadSuccess = true;
URL url = new URL(f_url[0]);
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a typical 0-100%
// progress bar
int lengthOfFile = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url.openStream(),
8192);
// Output stream
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES);
File file = new File(path, mModel.getTitle() + ".mp3");
OutputStream output = new FileOutputStream(file);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress("" + (int) ((total * 100) / lengthOfFile));
// writing data to file
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
mDownloadSuccess = false;
}
return null;
}
Thanks 谢谢
Solved it. 解决了。 It appears that the uses-permission is case sensitive It should have been:
看来use-permission区分大小写,应该是:
I have no idea why it managed to save it on the emulator. 我不知道为什么它设法将其保存在模拟器上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.