Android: EACCES 在铃声文件夹中保存文件的权限被拒绝
Android: EACCES Permission denied to save a file in the ringtones folder
我正在尝试使用流从 Web 下载 MP3 文件并使用此方法将其保存到铃声文件夹
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES)
我已经添加了所需的权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.write_external_storage"/>
当我在模拟器上检查我的应用程序时(我目前使用的是 Andy),该应用程序运行良好。
当我在实际设备(不止一个)上检查它时,我没有得到许可:
/storage/sdcard0/Ringtones/MyRingtone.mp3:打开失败:EACCES(权限被拒绝)
有人知道缺少什么吗?
完整的下载方法如下:
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;
}
谢谢
解决了。
使用许可似乎区分大小写
它应该是:
我不知道为什么它设法将它保存在模拟器上。
我正在尝试使用流从 Web 下载 MP3 文件并使用此方法将其保存到铃声文件夹
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES)
我已经添加了所需的权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.write_external_storage"/>
当我在模拟器上检查我的应用程序时(我目前使用的是 Andy),该应用程序运行良好。 当我在实际设备(不止一个)上检查它时,我没有得到许可: /storage/sdcard0/Ringtones/MyRingtone.mp3:打开失败:EACCES(权限被拒绝)
有人知道缺少什么吗?
完整的下载方法如下:
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;
}
谢谢
解决了。 使用许可似乎区分大小写 它应该是:
我不知道为什么它设法将它保存在模拟器上。