无法在Android中为flutter_downloader打开下载的文件
我正在尝试通过 flutter_downloader 下载一个虚拟的 .mp4(或任何文件)。这是我的代码片段
void mobileDownload(filename) async {
final status = await Permission.storage.request();
if (status.isGranted){ //user grants download permission
final storagePath = await getExternalStorageDirectory();
print(storagePath!.path);
final taskId = await FlutterDownloader.enqueue(
url: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4',
savedDir: storagePath.path,
fileName: '$filename.mp4',
showNotification: true,
openFileFromNotification: true,
);
}
}
通过编写通用回调(与此处提供的回调相同https://pub.dev/packages/flutter_downloader),我可以看到我的文件正在下载,进度显示为
D/DownloadWorker( 6368): Update too frequently!!!!, this should be dropped
I/flutter ( 6368): 97
D/DownloadWorker( 6368): Update notification: {notificationId: 10, title: testApp.mp4, status: 2, progress: 100}
D/DownloadWorker( 6368): insert description= _display_name=testApp.mp4 datetaken=1625756663182 mime_type=video/mp4 _data=/storage/emulated/0/Android/data/com.example.flutter_app/files/testApp.mp4 title=testApp.mp4 date_added=1625756663182 to MediaStore
I/flutter ( 6368): 100
D/DownloadWorker( 6368): Update too frequently!!!!, but it is the final update, we should sleep a second to ensure the update call can be processed
I/flutter ( 6368): 100
D/DownloadWorker( 6368): Update notification: {notificationId: 10, title: testApp.mp4, status: 3, progress: 100}
D/DownloadWorker( 6368): File downloaded
I/WM-WorkerWrapper( 6368): Worker result SUCCESS for Work [ id=01c89c79-31e1-4375-a594-6ddcc27b9681, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]
我也可以通过通知中心看到下载完成(https://imgur.com/q5FCRwN)
我的问题是我无法访问下载的文件,无论它们是 .mp4、.mp4、.pdf 还是其他格式。由于我将 openFileFromNotification 设置为 true,我不知道为什么我也无法从通知栏打开文件。我似乎也无法在 Files 应用程序中找到它们。
有什么建议?我在 AndroidManifest.xml 文件中设置了如下权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
编辑:查看 Github 上 flutter_downloader 的问题页面,它似乎不适用于 Android 11,这可能是我的问题。
编辑:无法在 Android 11 上使用它。决定改用 Dio 下载。如果有人也不能让它工作,这是一个很棒的教程:https : //www.youtube.com/watch?v=3gNd1Ma-gss&list=FLcgfafWRwPYXKs6NliCs5Xw&index=1&t=85s。除了该视频,本教程https://medium.com/@michallot/how-to-write-a-simple-downloading-app-with-flutter-2f55ae516867 还有助于显示通知。
THE END
二维码