如何在Flutter上为Android 10上的MediaStore(SDK 29)贡献文件? [英] How can I contribute files to MediaStore (SDK 29) on Android 10 in Flutter?
问题描述
我想将文件保存到Android用作默认Downloads目录的Download文件夹中.我发现可以通过使用
我该怎么做?这些文件似乎是在上述目录中创建的,但是我无法通过其他应用访问它们.
我对于开发Android相对较新,因此请提前对可能很愚蠢的问题感到抱歉...我无法通过阅读其他问题并谷歌搜索找到答案:/
Flutter的 path_provider
API由于Android 10及更高版本上的Android更改而遇到问题(未解决的问题).这应该是固定的-
https://github.com/flutter/flutter/issues/35783
就目前而言,通过Flutter获取iOS/Android Download
目录的最可靠方法似乎是-
字符串dir;if(Platform.isAndroid){dir ="/存储/模拟/0/下载/";//虽然不是很优雅,但是可以用}否则if(Platform.isIOS){dir =(等待getDownloadsDirectory()).path;}打印(目录);
希望这会有所帮助.
I want to save files to the Download folder used by Android as the default Downloads directory. I have found out that this should be possible by using MediaStore.downloads, but I have no clue how to do that in flutter! When using
List<Directory> android_dir =
await getExternalStorageDirectories(type: StorageDirectory.downloads);
String android_path = android_dir[0].path;
from the path_provider package, I seem to get a path to my application-specific directory
/storage/emulated/0/Android/data/com.mediaconverter/files/Download/
which doesn't seem easily accessible by the user through file browser apps.
Since Android 10 is deprecating ExtStorage.getExternalStoragePublicDirectory from the ExtStorage package, I am trying to find a way to accomplish saving files which can easily be accessed by the users. This is the folder which I want to target:
How can I accomplish that? The files seem to be created in the above-mentioned directory, but I can't access them through other apps.
I'm relatively new to developing for Android, so sorry in advance for the probably stupid question ... I couldn't find an answer by reading other questions and googling :/
Flutter's path_provider
API is experiencing problems (open issues) due to Android changes taking place for Android 10 and above. This should be fixed -
https://github.com/flutter/flutter/issues/35783
For now, the most reliable way of getting iOS/Android Download
directory via flutter seems to be this -
String dir;
if(Platform.isAndroid) {
dir = "/storage/emulated/0/Download/"; //not elegant, but it works
}else if(Platform.isIOS) {
dir = (await getDownloadsDirectory()).path;
}
print(dir);
Hope this helps.
这篇关于如何在Flutter上为Android 10上的MediaStore(SDK 29)贡献文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!