12

I tested this flutter app example: https://github.com/tensor-programming/flutter_read_write_file_and_path

But, browsing my device with a file-manager (Solid Explorer), I cannot find the file "db.txt" created by this example.

final path = await localPath;

I checked in many folders including:

  • /storage/emulated/0 (= sdcard)
  • sdcard/Android/data
  • sdcard/data

Where is this file? Should I root my device to find/see it?

What string to add after the "path" variable to reach the Download folder? Or, how to get the absolute path to the Download folder?

Device: GALAXY S8+ SM-G955F. Android 8.0. Not Rooted. Flutter beta v0.5.1. Dart 2.0.0-dev.58.0. Windows 10. Thanks and regards

user2192870
  • 509
  • 2
  • 5
  • 7

4 Answers4

11

If you're using a file explorer app installed on the device, then I don't believe you'll be able to access the files stored for a different app in it's Application Documents directory. This is part of the security model that isolates apps from each other.

If you have used Android Studio to build and deploy the app to your device, then you can got to View > Tool Windows > Device File Explorer with your device attached to your PC via USB to access these files.

I find for my own Flutter apps that the relevant path is /data/usr/0/…/app_flutter for the example you gave, this would be /data/usr/0/com.example.localstorageexample/app_flutter

(If you haven't used Android Studio to deploy the demo you reference, how did you get it on your device?)

Derek Lakin
  • 16,179
  • 36
  • 51
  • Is there any way to get the file using VSCode? – Deepam Gupta Apr 12 '20 at 18:21
  • You could use adb from the Terminal window: https://www.teamandroid.com/2018/08/02/transfer-files-android-devices-adb/ There is a Marketplace Extension for VSCode, too: https://marketplace.visualstudio.com/items?itemName=MakotoHamanaka.adb-filesystem NOTE: I haven't tried this myself. – Derek Lakin Apr 14 '20 at 09:31
4

You can do this

final Directory extDir = await getExternalStorageDirectory();
final String dirPath = extDir.path.toString().substring(0,20);
await Directory(dirPath).create(recursive: true);
final String filePath = '$dirPath/';

You might need to edit the parameters on the second line according to your platform for Android. This will create your file, and make it accessible to your users.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Sambit Majhi
  • 51
  • 1
  • 2
3

You can just take a look at the source file of the code.
In this case, only the documentation (/// marked comments) provides any useful information, which is the following:

I did not take a look into the project's code, which means that it might be possible that your file is not stored in getApplicationDocumentsDirectory().

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
  • When I click the /data folder I get the message: "Access denied". Is that mean I have to root my device to access this folder? – user2192870 Jul 19 '18 at 20:28
  • When I click the /data folder I get the message: "Access denied". Is that mean I have to root my device to access this folder? My Download folder is located there: `/storage/emulated/0/Download`. So to jump from `/data/data/` to Download I have to add this string: `../../../storage/emulated/0/Download`. Isn't it? – user2192870 Jul 19 '18 at 20:35
  • Open a command line. Enter `adb shell` to drop into... an adb shell. Enter `run-as ` to drop into a further shell (we need to go deeper) with access privs, located at the above double data directory. – Bondolin Sep 18 '21 at 00:57
3

Use: getExternalStorageDirectory(); And find storage directory instead. /storage

emmanuel
  • 31
  • 2