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.
Related
In my app I need to download some bills.
On IOS my users can easily find them when app is closed because it is stored in a dedicated folder easily findable. I achieve that with getApplicationDocumentsDirectory() from path_provider and the following option in plist :
<key>UISupportsDocumentBrowser</key>
<true/>
In android, downloaded files aren't put inside the download folder but inside the app data folder which is hard for a simple user to understand how to go in. What can I do to put bills (pdf) inside the Android Download folder ?
I use for the moment the method getExternalStorageDirectory() from path_provider for Android.
Based on #blackapps responses, I used the following hard coded path in Android and fallback to getExternalStorageDirectory() if folder didn't exist.
final Directory directory = Directory('/storage/emulated/0/Download');
if (!await directory.exists()) directory = await getExternalStorageDirectory();
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 am trying to make an app app that will be used to upload a file to the Firebase Storage. I don't want the user to have to choose a file instead i want to package the file with the app. (e.g in the raw/asssets folder).
I have tried several things and I can't make sense of anything. I have no direction. I watched a few tutorials on youtube but all of them use 'choose a file' method.
Any help is greatly appreciated.
You cannot get the absolute the path of the file located in assets. Because those files which are located inside the assets folder does not have the absolute path because they are packaged with the application. But you can use an AssetManager object to get an InputStream on an asset.
After looking all over google I haven't found a way of accessing Android internal storage from python.
I need to store an image generated by kivy app. I would like my python code to be able to navigate to a root user dir, create an app specific dir (if not found) and save the image there.
Simply creating a file with my device's path doesn't work. Should I be setting permissions for internal storage access? I'm lost with it.
You have something wrong in your code, you didn't paste the code nor logs, so... let's get it another way.
You can read/write with python just fine in the app folder (/data/data/org.something) with using:
app_folder = os.path.dirname(os.path.abspath(__file__))
To write to SD card you'll need to use App.user_data_dir, which as you can see in the docs on android gets you /sdcard/<app_name>. Not sure if it automatically creates it if it's missing, so it needs checking out probably. However, if it doesn't exist, just create it with python:
os.mkdir(App.user_data_dir)
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.