为什么下载管理器需要为`&maxSdkVersion GT WRITE_EXTERNAL_STORAG​​E`; 18 [英] Why download manager requires `WRITE_EXTERNAL_STORAGE` for maxSdkVersion > 18

查看:391
本文介绍了为什么下载管理器需要为`&maxSdkVersion GT WRITE_EXTERNAL_STORAG​​E`; 18的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下载管理器来下载文件并将其保存到这样的外部存储:

  DownloadManager.Request REQ =新DownloadManager.Request(URI);
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setDestinationInExternalFilesDir(TextReaderActivity.this,空,播客/+ Integer.toString(article.id)+ PODCAST_EXTENSION);

我得到了以下异常:

 例外:需要WRITE_EXTERNAL_STORAG​​E许可使用DESTINATION_FILE_URI:UID 10052没有android.permission.WRITE_EXTERNAL_STORAG​​E。

我读过,我并不需要请求 WRITE_EXTERNAL_STORAG​​E 权限 maxSdkVersion> 18 写外部目录时,为什么没有要求它在这里与下载管理器

更新:


  

在Android 4.4以上版本,规则是有点不同:结果
   - 要阅读或在getExternalFilesDir根的目录树写()
  和getExternalCacheDir(),则不需要许可结果
   - 要写到其他地方上的外部存储,你需要WRITE_EXTERNAL_STORAG​​E结果
   - 要从其他地方上的外部存储读取,您需要使用
  WRITE_EXTERNAL_STORAG​​E(如果你已经有一个)或
  READ_EXTERNAL_STORAG​​E(如果不是)



解决方案

这是你举有关的规则 WRITE_EXTERNAL_STORAG​​E 是时的您的流程的写到外部存储,然后只为你的 getExternalFilesDir()及相关目录。

在这种情况下,你是不是写到外部存储。你问下载管理器写到外部存储。 下载管理器—或者更准确地说,在过程下载管理器会谈—是需要你有这样的权限,它会出现不考虑API级别这样做。

I'm using Download manager to download file and save it to the external storage like this:

DownloadManager.Request req = new DownloadManager.Request(uri);
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setDestinationInExternalFilesDir(TextReaderActivity.this, null, "podcasts/" + Integer.toString(article.id) + PODCAST_EXTENSION);

I get the following exception:

Exception: need WRITE_EXTERNAL_STORAGE permission to use DESTINATION_FILE_URI: uid 10052 does not have android.permission.WRITE_EXTERNAL_STORAGE.

I've read that I don't need to request WRITE_EXTERNAL_STORAGE permission for maxSdkVersion > 18 when writing to external directories, why doesn't it require it here with DownloadManager?

UPDATE:

On Android 4.4 and up, the rules are a bit different:
- To read or write in the directory trees rooted at getExternalFilesDir() and getExternalCacheDir(), you do not need a permission
- To write to anywhere else on external storage, you need WRITE_EXTERNAL_STORAGE
- To read from anywhere else on external storage, you need either WRITE_EXTERNAL_STORAGE (if you already have that) or READ_EXTERNAL_STORAGE (if not)

解决方案

The rules that you cite regarding WRITE_EXTERNAL_STORAGE are for when your process writes to external storage, and then only for your getExternalFilesDir() and related directories.

In this case, you are not writing to external storage. You are asking DownloadManager to write to external storage. DownloadManager — or, more accurately, the process that DownloadManager talks to — is requiring you to have this permission, and it would appear to do so without regard to API level.

这篇关于为什么下载管理器需要为`&maxSdkVersion GT WRITE_EXTERNAL_STORAG​​E`; 18的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆