Since Android 11 restricts the freedom accesing the external storage, I've looked many solutions to convert following path which I receive from ACTION_OPEN_DOCUMENT_TREE intent: content://com.android.providers.downloads.documents/tree/msd%3A163975/document/msd%3A163975 to a path looking like this: storage/emulated/0/Downloads/TestFolder
Why do I need the absolute folder path?:
The user can choose a folder, where the app will create a backup ZIP file each day.
Since the user might forget which folder he selected, he should be read the absolute path of the folder he choose. content://com.android.providers.... is not really descriptive for the enduser.
According to some valid answers, android 10-11 prevent developers receiving the absolute path of a folder. Is that true?
Other solutions I tried executing without any success:
Get Real Folder Path from Document Tree Uri
Get Full Path From Uri
Related
I am developing File Manager, I have one issue in android version 30, when I get listFile() of OTG path its not return file, the only way to get all files is from DocumentFile, but now I want to get file as File from that DocumentFile how do I get, plz support me.
You don't. There's no promise that there is an actual File anywhere, it could be backed by a content provider calculating it at runtime, or reading it from a db. Since a File can only represent a file on disk, there's no way to convert from a DocumentFile to a File.
USB OTG drives are often not mentioned any more in getExternalFilesDirs().
So you have no path.
Only with SAF ACTION_GET_DOCUMENT_TREE you can get an uri to the drive or folders on the drive.
Now its pretty easy to convert such an uri to a flie system path.(Look at all kinds of getRealFileForUri() implementations).
But even if you manage to get a path it is not usable.
I am developing a Flutter app. I am trying to save a pdf file to the device's downloads directory.
The path looks like this: /storage/emulated/0/Download
Can I assume that all Android devices store downloads in this location, or are there exceptions?
It is usually a good idea to not just hardcode a path. the path_provider package will help you here. https://pub.dev/packages/path_provider
It lets you get the directory you are looking for like this:
import 'package:path_provider/path_provider.dart' as pathProvider;
String dir = (await pathProvider.getDownloadsDirectory()).path;
It of course also works for iOS and lets you get the path for many different directories.
I have a file gpac.xlsx in the internal storage of my phone. I want to get its path. In android, it's confusing. Which one of these is the correct path?
/data/sdcard0/gpac.xlsx
/data/emulated/0/gpac.xlsx
Or some other besides these?
I have a file gpac.xlsx in the internal storage of my phone.
Based on your sample paths, your file is in what the Android SDK refers to as external storage.
I want to get its path.
new File(Environment.getExternalStorageDirectory(), "gpac.xlsx");
Which one of these is the correct path?
It could be either of those or something else. Use the Java snippet shown above to derive the proper path at runtime for the particular device that your code happens to be running on.
I'm trying to download a big zip file directly inside the external storage directory, for example
"/mnt/sdcard/Android/data/com.vexdev.audioguida.app/files/data"
i guess i should be using
DownloadManager.Request.setDestinationInExternalPublicDir(path, fileName)
but i don't know how to provide it with a path that is consistent across different android devices.
AND i'm also trying to get a path to access this file later, like this:
File file = new File(path + fileName);
i'm asking here because i know that those two methods are expecting different rooted paths, because i tried to provide a path like this:
Application.getAppContext().getExternalFilesDir(Environment.getDataDirectory().getAbsolutePath()).getAbsolutePath();
but the DownloadManager was not putting the files where the File constructor was searching it later. (It was downloading in the wrong directory actually!)
I'm looking for a way to download those files directly in the right directory, without having to move them.
i guess i should be using DownloadManager.Request.setDestinationInExternalPublicDir(path, fileName)
Not for the location you suggested. The closer match would be setDestinationInExternalFilesDir().
but i don't know how to provide it with a path that is consistent across different android devices.
There isn't even a path that will be consistent within one device, as different accounts will use different paths. For example, the path you typed into your question might be used on some devices for some accounts, but the details will vary.
i'm also trying to get a path to access this file later
That is covered in the DownloadManager.Request documentation:
setDestinationInExternalFilesDir() maps to getExternalFilesDir() on Context
setDestinationInExternalPublicDir() maps to getExternalStoragePublicDirectory() on Environment
i tried to provide a path like this
That is not how you use getExternalFilesDir(). Please read the JavaDocs to see what valid values are for the parameter to that method. getDataDirectory() is not a valid value.
I'm using HTC Dream and trying to read the images stored in the "default" album folder of this phone. But I've yet to found out what's the folder path to those images file.
When I mount the phone to my comp, some of the default images are in:
/E0FD-1813/DCIM/
and the photos taken using the phone are stored in
/E0FD-1813/DCIM/100MEDIA/
But using those paths, accessing the images throws a "No Such File" error.
So
do you know what's the path to that image folder? What would be the path patterns (if any) in other Android phones?
I don't need to set any additional permission to access those files, do I?
Do you know how I can build a "file browsing" widget in my activity? I've searched and seems like there is no such widget and I've to install app that does file browsing. In any case, how to incorporate that as a file-browsing view in my current activity?
Thanks for your kind advice!
But I've yet to found out what's the folder path to those images file.
There is no single folder.
do you know what's the path to that image folder?
There is no single folder. Use the MediaStore content provider.