Android Question how to get a photo list

sz4t4n

Member
Licensed User
Longtime User
Hello,

i know path of my photos ("/storage/emulated/0/DCIM/Camera/") and i want to have list of all images in this folder. I tried with this ->

B4X:
Dim mylist As List
    mylist.Initialize
    mylist = File.ListFiles("/storage/emulated/0/Camera/")
    Log(mylist)

but I always get in logs -> (list) not initialized

any ideas?
 

mangojack

Expert
Licensed User
Longtime User
Hello,

i know path of my photos ("/storage/emulated/0/DCIM/Camera/")

Then you call ..
B4X:
    mylist = File.ListFiles("/storage/emulated/0/Camera/")

Notice anything strange ?


Also .. You do realize this path will be different on other devices.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
As well as mangojack have told you, I think probably you should have in mind runtime permissions too, to access an external folder.

Method_636.png
File. ListFiles (Dir As String) As List

Returns a read only list with all the files and directories which are stored in the specified path.
An uninitialized list will be returned if the folder is not accessible.
 
Upvote 0

sz4t4n

Member
Licensed User
Longtime User
Thanks for help, it was permission problem. Now i got list.

Also .. You do realize this path will be different on other devices.

Yes i know and I use this code ( written by Erel)

B4X:
Sub GetExternalStoragePublicDirectory (name As String) As String
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Environment")
    Dim path As Object = jo.RunMethod("getExternalStoragePublicDirectory", Array(name))
    If path = Null Or File.Exists(path, "") = False Then
        Log("No such folder.")
        Return ""
    End If
    Return path
End Sub

B4X:
GetExternalStoragePublicDirectory("DCIM")
 
Upvote 0
Top