I am trying to get a list of all the Audio files on a device with the following code but I am baffled. On one device it returns the files from ONE directory but there are a dozen directories all in the same place and there are files in the PARENT of the returned directory and they are not returned. All files were copied to the device from windows at the same time. On another device I get the same result + the addition of all the files in the File path: /storage/emulated/0/Notifications AND a number of files in several subdirectories of Notifications that are hidden in file manager. I can get what I need with external storage but it is incredibly slow. One source said you need to force media manager to refresh and I found code which purported to do that (thank you Copilot) but it made no difference (Copilot, Oh well). I can get what I need with External Storage lib but it is slow. Any thoughts and ideas appreciated.
Pixel 7/Samsung Galaxy 7 lite are what I am testing on.
You can see in the commented code a partial list of the things I tried none of which made a difference.
Pixel 7/Samsung Galaxy 7 lite are what I am testing on.
You can see in the commented code a partial list of the things I tried none of which made a difference.
B4X:
' Obtain application context.
Dim context As JavaObject
context.InitializeContext
' Get the ContentResolver from the context.
Dim cr As JavaObject = context.RunMethod("getContentResolver", Null)
' Initialize the MediaStore.Audio.Media static class.
Dim mediaStoreAudio As JavaObject
mediaStoreAudio.InitializeStatic("android.provider.MediaStore$Audio$Media")
' Get the external audio content URI.
Dim uri As Object = mediaStoreAudio.GetField("EXTERNAL_CONTENT_URI")
' Define the projection columns.
' Dim projection() As String = Array As String("TITLE", "_data", "DURATION", "ARTIST", "ALBUM")
Dim projection() As String = Array As String("TITLE", "_data", "DURATION", "ARTIST", "ALBUM")
' Perform the query.
' Dim selection As String = "MIME_TYPE LIKE 'audio/%'"
' Dim selection As String = "_data LIKE ?"
' The selection argument uses a wildcard (%) after the directory path.
' Dim selectionArgs() As String = Array As String("audio" & "/%")
' Dim cursor As JavaObject = cr.RunMethod("query", Array(uri, projection, selection, selectionArgs, Null))
Dim cursor As JavaObject = cr.RunMethod("query", Array(uri, projection, Null, Null, Null))
If cursor = Null Then
Log("Cursor is null; check that permissions are granted and MediaStore has scanned the files.")
Return
End If