Android Question how to list files in directory when using Open_Document_tree with Intent

mcqueccu

Well-Known Member
Licensed User
Longtime User
I have been researching how some apps have been able to access some directories, I got to this point.
Now my issue, listing files in the chosen location.


B4X:
Sub ion_Event (MethodName As String, Args() As Object) As Object
    'Args(0) = resultCode
    'Args(1) = intent data
   
    If -1 = Args(0) Then      
        Log(Args(1)) 'Intent { dat=content://com.android.externalstorage.documents/... flg=0xc3 }
       
        Dim folderUri As Intent = Args(1)
        Log(folderUri.GetData) 'content://com.android.externalstorage.documents/tree/primary%3APodcasts
       
       
        ''Persist permission - Code from ChatGPT
        Dim flags As Int = Bit.Or(folderUri.Flags, 1) ' READ Permission
        flags = Bit.Or(flags, 2)                      ' WRITE Permission
       
        'TODO: List Files from the location
   
    Else
        Log("Folder selection was canceled.")
        Return Null
    End If
   
End Sub
 
Last edited:

drgottjr

Expert
Licensed User
Longtime User
after you have the uri, you pass it to documentfile. if android lets you look at the directory, you can list the files. look for documentfile in our sdk. if you have the latest sdk, you'll see it. include it in the project as an #additional jar. works no problem (except for android's not letting you look in certain (many) directories.
 
Upvote 0
Top