Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get access to files in download directory in Android App

I am writing an android App. In the app I need access to the download directory \DOWNLOAD. I can read and write files within the app directory and I see the DOWNLOAD directory when I request the files within root directory. But when I use

 File[] files = new File("\DOWNLOAD").listFiles();

the result is not a valid array but null.

I added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

to the AndroidManifest.xml and I enabled the Storage permission on the phone.

What else must I do to get access to the files in download directory?

Kind regards, Wolfgang

like image 533
Wolfgang Wieser Avatar asked Dec 08 '25 05:12

Wolfgang Wieser


1 Answers

It seems that adding

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

is not sufficient. Now I additionally request this permission on runtime with following code:

String[] requiredPermissions = { Manifest.permission.READ_EXTERNAL_STORAGE };    
ActivityCompat.requestPermissions(this, requiredPermissions, 0);

and it works again :)

like image 156
Wolfgang Wieser Avatar answered Dec 10 '25 18:12

Wolfgang Wieser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!