且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到getApplicationDocumentsDirectory()提供的路径

更新时间:2023-11-18 22:21:22

如果您正在使用设备上安装的文件浏览器应用程序,那么我认为您将无法访问为其他文件存储的文件应用程序在其应用程序文档"目录中.这是将应用程序彼此隔离的安全模型的一部分.

如果您使用Android Studio来构建应用并将其部署到设备上,则可以访问查看> 工具Windows > 设备文件资源管理器,并将您的设备通过USB连接到PC,以访问这些文件.

对于我自己的Flutter应用程序,对于您给出的示例,我发现相关路径为/data/usr/0/…/app_flutter,这将是/data/usr/0/com.example.localstorageexample/app_flutter>

(如果您尚未使用Android Studio部署您引用的演示,那么如何在设备上获取它?)

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

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?)