Jump to content
dmitrybv

Android. TDirectory.GetFiles('/storage/emulated/0/DCIM/Camera') returns an empty list

Recommended Posts

Good day.

 

Embarcadero® RAD Studio 12 Version 29.0.55362.2017 

Android 13, Samsung S20.


I have files taken by the camera in the folder '/storage/emulated/0/DCIM/Camera' on my phone.


How to set up the Android application correctly so that I can get a list of these files?


When creating an Fmx application by default, the command TDirectory.GetFiles('/storage/emulated/0/DCIM/Camera') returns an empty list.

Share this post


Link to post

TPath.GetCameraPath() returns the following value - '/storage/emulated/0/Android/data/com.embarcadero.EhLib_Fmx_MainDemo/files/DCIM'.
When viewing from the program via TDirectory.GetFile, this folder does not contain files.
When viewing from the phone, I cannot access the folder ‘/storage/emulated/0/Android/data/com.embarcadero.EhLib_Fmx_MainDemo’ at all.

Share this post


Link to post

Is there a Demo project in RAD Studio Samples or on github.com that demonstrates the ability to view photos in the app taken via the camera?
Perhaps the TDirectory.GetFile method on Android does not work correctly or the app should request some rights via User Persmissions.

Share this post


Link to post
12 hours ago, dmitrybv said:

TPath.GetCameraPath() returns the following value - '/storage/emulated/0/Android/data/com.embarcadero.EhLib_Fmx_MainDemo/files/DCIM'.
When viewing from the program via TDirectory.GetFile, this folder does not contain files.
When viewing from the phone, I cannot access the folder ‘/storage/emulated/0/Android/data/com.embarcadero.EhLib_Fmx_MainDemo’ at all.

I'm no expert but that looks like you have not gotten permissions.

Share this post


Link to post
On 4/7/2025 at 6:48 AM, dmitrybv said:

How to set up the Android application correctly so that I can get a list of these files?

I've created a demo in my HowTo repository. It also demos a way of accessing the contents of the files, since you cannot use the "traditional" methods of accessing the files in Delphi.

  • Like 1

Share this post


Link to post

Hello, Dave

Thanks for the demo project.


Is there a more universal way to view the list of files in Android folders?
Regarding the TDirectory.GetDirectories(), TDirectory.GetFiles() methods, I noticed that the TDirectory.GetDirectories('/storage/emulated/0/') method returns a list of folders similar to what is visible in the Files by Google program.
Files by Google displays files in folders such as:
'/storage/emulated/0/DCIM/Camera'
'/storage/emulated/0/DCIM/Screenshots'
'/storage/emulated/0/Documents'
'/storage/emulated/0/Download'
but the TDirectory.GetFiles() method does not return any files when specifying any path.


What method should be used in Android to get a list of files in a folder?

Share this post


Link to post
51 minutes ago, dmitrybv said:

What method should be used in Android to get a list of files in a folder?

It depends on the folder. If it's private to the app (e.g. via TPath.GetDocumentsPath) then TDirectory.GetFiles will work. If the folder is shared (as are those that you listed), then a method similar to what is in the demo could be used, i.e. via ContentResolver. 

Share this post


Link to post
Posted (edited)
7 hours ago, Dave Nottage said:

If the folder is shared (as are those that you listed), then a method similar to what is in the demo could be used, i.e. via ContentResolver. 

Actually, there is more to this. If you need access to files other than audio, images and video that are not created by your app, you would need to use the relevant action(s), as described here. This kind of thing is implemented in the FilesSelector feature in Kastri.

 

 

Edited by Dave Nottage
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×