You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Android DownloadManager.enqueue()时触发SecurityException权限异常

解决DownloadManager.enqueue()触发的SecurityException问题

问题根源

从报错信息和Manifest配置来看,问题出在权限名称拼写错误:你在Manifest中声明的权限是android.permision.INTERNET,其中permision少了一个s,正确的权限名称应为android.permission.INTERNET。系统无法识别错误的权限声明,导致调用DownloadManager.enqueue()时触发权限拒绝的SecurityException。

修复步骤

  1. 打开项目中的AndroidManifest.xml文件
  2. 找到权限声明行,将错误的权限名称修正为正确格式
  3. 重新编译并运行项目

修正后的权限声明示例

<uses-permission android:name="android.permission.INTERNET"/>

补充说明

你的DownloadManager调用逻辑本身没有问题:

private fun startDownload() { 
    custom_button.buttonState = ButtonState.Clicked
    val request = DownloadManager.Request(Uri.parse(url))
        .setTitle(getString(R.string.app_name))
        .setDescription(getString(R.string.app_description))
        .setAllowedOverMetered(true)
        .setAllowedOverRoaming(true)
    val downloadManager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager 
    downloadID = downloadManager.enqueue(request)
}

修正权限拼写后,系统就能正确识别INTERNET权限,enqueue()方法即可正常执行下载请求。

内容的提问来源于stack exchange,提问作者kk2004

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 14:50:24