flutter_downloader下载完成后通知错误显示失败且点击无跳转求助
Flutter Downloader 通知显示失败且点击无法跳转问题
我使用flutter_downloader: ^1.9.1实现文件下载,文件能成功保存到Download文件夹,但存在两个问题:
- 下载完成后通知错误显示为失败状态
- 点击该通知无法跳转至下载文件夹
下载代码
void _download(String url) async { final status = await Permission.storage.request(); if (status.isGranted) { final externalDir = await getExternalStorageDirectory(); final id = await FlutterDownloader.enqueue( fileName: "LRMonoPhase4.mp3", url: 'https://www.kozco.com/tech/LRMonoPhase4.mp3', savedDir: '/storage/emulated/0/Download', showNotification: true, openFileFromNotification: true, ); } else { print('Permission Denied'); } }
Android Provider配置
<provider android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider" android:authorities="im.mingguang.mingguang_app.flutter_downloader.provider" android:exported="false" android:grantUriPermissions="true" android:requestLegacyExternalStorage="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>
日志片段
D/DownloadWorker( 4447): DownloadWorker{url=https://www.kozco.com/tech/LRMonoPhase4.mp3,filename=LRMonoPhase4.mp3,savedDir=/data/user/0/com.rsoft.salezrobot/app_flutter,header={},isResume=false,status=ENQUEUED D/DownloadWorker( 4447): Update notification: {notificationId: 10, title: LRMonoPhase4.mp3, status: RUNNING, progress: 0} D/DownloadWorker( 4447): Open connection to https://www.kozco.com/tech/LRMonoPhase4.mp3 D/DownloadWorker( 4447): Headers = {} D/TrafficStats( 4447): tagSocket(172) with statsTag=0xffffffff, statsUid=-1 D/EGL_emulation( 4447): app_time_stats: avg=21.56ms min=5.27ms max=97.80ms count=47 I/trustAllHosts( 4447): checkServerTrusted D/DownloadWorker( 4447): Content-Type = audio/mpeg D/DownloadWorker( 4447): Content-Length = 931630 D/DownloadWorker( 4447): Charset = null D/DownloadWorker( 4447): fileName = LRMonoPhase4.mp3 D/DownloadWorker( 4447): Update notification: {notificationId: 10, title: LRMonoPhase4.mp3, status: RUNNING, progress: 1} D/EGL_emulation( 4447): app_time_stats: avg=19.26ms min=7.83ms max=39.89ms count=52 D/DownloadWorker( 4447): Update too frequently!!!!, this should be dropped D/DownloadWorker( 4447): Update too frequently!!!!, this should be dropped
相关截图
- 通知显示失败状态:

- 文件已成功保存到Download文件夹:

解决方案
1. 通知显示失败问题
从日志可见,代码指定的/storage/emulated/0/Download被实际重定向到了/data/user/0/com.rsoft.salezrobot/app_flutter,这是Android 10+存储权限限制导致的路径不一致。
- 确保
AndroidManifest.xml的<application>标签下添加android:requestLegacyExternalStorage="true"(仅在provider中配置无效) - 用
path_provider获取正确的公共下载目录,替换硬编码路径:import 'package:path_provider/path_provider.dart'; // 替换原路径获取代码 final downloadDir = await getExternalStoragePublicDirectory(DirectoryDownloads); final savedDir = downloadDir.path; - Android 13+需额外请求
Permission.downloads权限,使用permission_handler最新版本处理权限逻辑。
2. 通知点击无法跳转问题
核心是File Provider配置不匹配,导致无法正确访问下载文件:
- 检查
res/xml/provider_paths.xml,确保包含Download目录的访问路径:<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="external_files" path="."/> <external-files-path name="download_files" path="Download"/> </paths> - 确认
android:authorities的值与应用包名一致,且Provider在<application>标签下正确注册 - 避免硬编码路径,确保File Provider能正确解析文件URI
额外建议
- 将
flutter_downloader升级到最新稳定版,旧版本存在较多通知和路径相关的已知bug - 测试前清理应用缓存并重新安装,避免旧配置残留
内容的提问来源于stack exchange,提问作者Anandh Krishnan
相关产品推荐
相关产品推荐

