Flutter-将文件保存到下载文件夹-downloads_path_provider [英] Flutter - save file to download folder - downloads_path_provider

查看:564
本文介绍了Flutter-将文件保存到下载文件夹-downloads_path_provider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flutter开发移动应用程序.为此,我使用了 downloads-path-provider 来获取手机的下载目录.仿真器返回/storage/emulated/0/Download.同样,当我将文件保存在此目录中时,该文件也可以在下载"文件夹中看到.

I'm developing a mobile app using flutter. For that I used downloads-path-provider to get the download directory of the mobile phone. The emulator returns /storage/emulated/0/Download. Also when I save a file in this directory the file can be visible in the Download folder.

但是在实际设备上,它还会返回相同的目录路径. /storage/emulated/0/Download这对实际设备是否正确?因为在实际设备上,我在下载"文件夹中看不到保存的文件.

But on a real devices it also returns the same directory path. /storage/emulated/0/Download Is this correct for the actual devices? Because on actual devices I cannot see the saved file in the Download folder.

有什么解决方案可以在真实设备上找到下载目录吗?

Is there any solution to find the downloads directory on a real device?

推荐答案

path_provider可能很快会发生一些变化,存在一些未解决的问题:

path_provider will probably undergo some changes soon, there are some open issues:

https://github.com/flutter/flutter/issues/35783

截至目前,在Android设备上获取下载路径的最佳方法是使用:

As of right now, the best way to get the download path on an Android device is to use:

/storage/emulated/0/Download/

不需要.

并在Android中获取外部目录路径:

And to get the external dir path in Android:

/storage/emulated/0/

模拟"的这个词并不意味着它是仿真器路径,而只是一个命名约定.

The "emulated" word does not mean it's the emulator path, it's just a naming convention.

确保您具有写入文件的权限,并将其添加到manifest.xml文件中的< manifest标记下:

Make sure you have permission to write to the file, add this to manifest.xml file, under <manifest tag:

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

,并在运行时请求权限.

and also request permission at run time.

请参见 https://pub.dev/packages/permission_handler

这篇关于Flutter-将文件保存到下载文件夹-downloads_path_provider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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