问题
In a Flutter project, how to get the (absolute) path to the Download folder in my Android device? My Download folder is next those one: Alarms, Android, data, DCIM, Documents, Movies, Music, Notifications, Pictures, ...
Device: GALAXY S8+ SM-G955F. Android 8.0. Not Rooted. Flutter beta v0.5.1. Dart 2.0.0-dev.58.0. Windows 10
File manager showing my Download folder
Using this package path_provider
I got those 3 paths:
/data/user/0/com.exemple.fonzo/cache
/data/user/0/com.exemple.fonzo/app_flutter
/storage/emulated/0
I cannot find or access those 3 folders from Solid-Explorer file manager on my un-rooted device GALAXY S8+ SM-G955F. Android 8.0. I just want to find the absolute path to a folder (like Download) that:
- I can access with my Android file manager app.
- I can write files in this folder from my flutter project.
回答1:
You could use the downloads_path_provider package. You will have add <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
to your AndroidManifest.xml. Also if you plan to write into that folder and want your application to work for android version > 6 you must ask the user for writing permission. You could do that with https://pub.dev/packages/permission_handler.
await PermissionHandler().requestPermissions([PermissionGroup.storage]);
回答2:
Change the function getApplicationDocumentsDirectory()
to getExternalStorageDirectory()
it should show the external directory for the app.
回答3:
I used this library to get public download directory in Android
ext_storage
String _getPathToDownload() async {
return ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_DOWNLOADS); print(path); // /storage/emulated/0/Download
}
回答4:
In Flutter
https://pub.dev/packages/ext_storage
Installation Add ext_storage as a dipendency in your project pubspeck.yaml.
dependencies:
ext_storage:
Usage First, you write import ext_storage package.
import 'package:ext_storage/ext_storage.dart';
void dirpath() async {
var path = await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_DOWNLOADS);
}
回答5:
You should use native feature.
At time, to access phone directory is provided by path_provider
package .
With it, you can acceess: temporary directory, app directory, external storage.
Doc: https://pub.dartlang.org/packages/path_provider
来源:https://stackoverflow.com/questions/51776109/how-to-get-the-absolute-path-to-the-download-folder