0

hello, community I'm new in Stackoverflow, but many times I used it to find solutions to my questions (usually in Delphi). Today I'm new in Android Studio. I try to get the list files in an Android device using this code, from here: How to list files in an android directory?

String path = Environment.getExternalStorageDirectory().toString()+"/Pictures";
Log.d("Files", "Path: " + path);
File directory = new File(path);
File[] files = directory.listFiles();
Log.d("Files", "Size: "+ files.length);
for (int i = 0; i < files.length; i++)
{
    Log.d("Files", "FileName:" + files[i].getName());
}

Apparently, it works, but I get only a Thumbnails file from /storage/emulated/0/Pictures but in the real folder from the device (MainStorage/Pictures) there are some Image files. I found this path using the App "File Manager +". I don't refer to a collection of images scattered in different folders. There are no more folders named 'Pictures' in the whole device. I know probably I do some basic things wrong but my inexperience in Android prevents me from discovering what it is. The device works in Android 11, but the minimum requirements for the project are Android 6

In advance, thank you very much.

  • Is it an Android 11 device? – blackapps Mar 02 '22 at 07:07
  • `actual folder` Actual folder? `(Galaxy Tab A7\Tablet\Pictures)` That is no valid full path. Where did you get it from? Use a file manager app that tells you the real full paths. – blackapps Mar 02 '22 at 07:10
  • Further: any Android device has software where you can choose to see Images, Videos, Music or Documents. But those are not real folders. Files you see can reside everywhere on the device. They are collections – blackapps Mar 02 '22 at 07:18
  • Thanks for your interest, backapps. Yes, the device works in Android 11. I've edited the question in order to clarify these doubts. Sorry if I've not been enough explicit in the first attempt – Pei Iborra Mar 02 '22 at 14:54
  • `I don't refer to a collection of images scattered in different folders. There are no more folders named 'Pictures' in the whole device. I` That does not matter. Under a collection 'Images' or 'Pictures' the device could show pictures from the whole device. From all folders. – blackapps Mar 02 '22 at 14:58
  • You said nothing about obtaining storage read permissions. – blackapps Mar 02 '22 at 14:59
  • Further you should understand that since Android 11 the owner of a file is important. If a file is created by an app then other apps usually cannot 'see' them. Media files are often visible but not always. Also files you place on your Android device using a PC are not visible for apps as the app is not the owner then. – blackapps Mar 02 '22 at 15:03
  • `real folder from the device (MainStorage/Pictures)` That is not the path to a real folder. That is not a path a programmer can use. /storage/emulated/0/Pictures is a path. Find the real path if you use a file manager. – blackapps Mar 02 '22 at 15:05
  • I reaffirm that I have never been looking at any collection. I am seeing the list of images (not the images themselves) of the folder through the "File Manager +" App that does not use collections and allows me to navigate between the different folders I know the behaviour of many Apps showing collections of images or videos, etc. it is not the case at hand. I am simply trying to get the files from a folder. What I get using the above procedure does not match the actual files in that folder. – Pei Iborra Mar 02 '22 at 18:44
  • : I already put the corresponding permission in the manifest, I think: – Pei Iborra Mar 02 '22 at 18:51
  • : This could be the reason why I don't see the images, which have actually been uploaded via PC. But then I don't understand how the "File Manager +" app can see them. Maybe some extra permission is missing – Pei Iborra Mar 02 '22 at 18:55
  • <(MainStorage/Pictures) That is not the path to a real folder>: Since "File Manager +" didn't let me see the real path, I downloaded a more complete File Manager. Effectively, the correct path is /storage/emulated/0/Pictures and there are the images that I want to list with my app. So, the problem is that the mentioned procedure does not see them – Pei Iborra Mar 02 '22 at 19:11
  • Well at least you now know why you dont see them ;-) – blackapps Mar 02 '22 at 19:34
  • `I already put the corresponding permission in the manifest, ` That is not enough as you should know – blackapps Mar 02 '22 at 19:35
  • Ok, many thanks, @blackapps then I will search how to do with Android 11. If I can't find the answer, I will put a new appropriate question – Pei Iborra Mar 02 '22 at 21:41
  • You will only see them with permission MANAGE_EXTERNAL_STORAGE. – blackapps Mar 02 '22 at 21:44

0 Answers0