[英]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;
}
謝謝
解決了。 看來use-permission區分大小寫,應該是:
我不知道為什么它設法將其保存在模擬器上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.