Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store files generated from app in "Downloads" folder of Android?

Tags:

android

I am generating an excelsheet in my app which when generated should be automatically saved in the "Downloads" folder of any android device where all the downloads are typically saved.

I have the following which saves the file under "My Files" folder -

File file = new File(context.getExternalFilesDir(null), fileName); 

resulting in -

W/FileUtils﹕ Writing file/storage/emulated/0/Android/data/com.mobileapp/files/temp.xls 

I rather want to save the generated file automatically in the "Downloads" folder when the excel sheet is generated.

Update # 1: Please see the snapshot here. What I want is the one circled in red and what you suggested gets stored in the one circled blue (/storage/emulated/0/download) if that makes sense. Please advise on how I can save a file in the one circled red i.e., "Downloads" folder which is different from /storage/emulated/0/Download under "MyFiles"

snapshot

like image 529
sunskin Avatar asked Jan 28 '15 03:01

sunskin


People also ask

Where are app downloads stored on Android?

You can find your downloads on your Android device in your My Files app (called File Manager on some phones), which you can find in the device's App Drawer. Unlike iPhone, app downloads are not stored on the home screen of your Android device, and can be found with an upward swipe on the home screen.


1 Answers

Use this to get the directory:

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); 

And don't forget to set this permission in your manifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
like image 126
Oluwatumbi Avatar answered Sep 22 '22 20:09

Oluwatumbi