Android Question file.listfiles not working. only returns one file

apti

Member
I have posted my code below
the MusicFolder is /storage/emulated/0/Music

I get one item called thumbnails but no files in the music folder. The size shows as 1 as in 1 file and there are more than that there when I look. I am an experienced programmer but somewhat new to B4X so I am fairly sure I am missing something stupid. Would somebody be kind enough to point out the stupid thing I am missing or not doing?


problem child:
private Sub LoadSongs
    Dim S As List
    Dim I As Int
    
    lsSongs.Clear  <------------ this is just a listview
    If MusicFolder<>"" Then
        
        s=File.ListFiles(MusicFolder )
        Log("Songs = "&S.Size)
        For I=0 To S.Size-1
            lsSongs.AddTextItem(S.Get(I),Null)
            Log("Song = "&S.Get(I))
        Next
    End If
End Sub
 
Solution
found it. had to request permission to read and now I get what I expected. I think we need a better way to do permissions as it took 2 days to find the right one and make it work.

apti

Member
No one should use ListView.

What is the output of:
B4X:
Log(MusicFolder)
Log(File.ListFiles(MusicFolder))
sorry, listview is the generic name I used. it was the custom list thing but that does not change anything in why I can't see the files. I would assume a user has permission to access his own files in android but seeing the abomination google made out of it, maybe I am wrong.

results...

log(musicfolder) ---- just what I noted in the code... /storage/emulated/0/Music

log(file.listfiles(MusicFolder) = [.thumbnails]


the count is 1. I know there is music there I put it there to test. I can see it in file managers.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot access the external storage directly. You need to use ContentChooser or ExternalStorage.

 
Upvote 0

apti

Member
You cannot access the external storage directly. You need to use ContentChooser or ExternalStorage.

of course not. Why would google make something that worked right. They took a version of Linux and turned it into an abomination. Turn something simple into something near impossible. Sorry for the rant.

I looked at your example posted but not seeing where I would be able to choose a folder from the users file area. I just want to get a listing of what is in the chosen folder. I can get to the point of choosing the folder just not able to access it. Is there something somewhere that has an example of how to get the folder listing?

I have noticed that you need permission to do pretty much anything in android including to your own stuff. Is there a place to find what all these permissions are? such as a list and how to request the permission?

more rant:
I might need to know the permission to go to the bathroom too, anybody know what that one is?
 
Upvote 0

apti

Member
found it. had to request permission to read and now I get what I expected. I think we need a better way to do permissions as it took 2 days to find the right one and make it work.
 
Upvote 0
Solution
Top