Android Question File Picker

JeffT

Member
Licensed User
I am in need of a file choosing dialog - surprised not to see one built in
I have downloaded and tried FilePicker, but it crashes as soon as I click the button in the example project.

(Reading the docs, it says that the first parameter is 'event' but doesnt say what the event is supposed to do, or how it needs to be defined.
Is that some kind of callback?
Does it have parameters?)

How have others implemented a button that 'gets a file'?
 

JeffT

Member
Licensed User
You should use ContentChooser (Phone library) to let the user choose "resources".
Thanks
I can get that dialog to show.

But this seems to only allow for files that have a known mime type, or a known 'launching application'


The app I am trying to write needs to open files of my own extension (OXS)
If I use ("OXSfiles/* as the first parameter of the .Show , I see no files listed , even though I placed one in Downloads as a test
If I use ("*" .. I get a 'no applications can handle ...' message

Can I define my own mime type?
Cant I select 'any file from downloads that I want' (eg how would a hexedit application work)

(I'm building a prototype in B4A as a proof of concept. If I can get things working, the plan is to buy into and develop for B4i on iPads
But on iPads, I have run into 'only being able to access files that exist in Shared Documents for this app' - customers hate that - they want to be able to browse for files in the Files area or iCloud, so thats what I want to be able to do)
 
Upvote 0

agraham

Expert
Licensed User
You can also use FileDialog from the Dialogs library
I suggest you use Dialogs2 , it has some improvements.
 
Upvote 0

Brian Dean

Active Member
Licensed User
The app I am trying to write needs to open files of my own extension (OXS)

If you are looking for files with a particular extension then maybe you can do something like this ...
B4X:
Dim found as List

. . .

Private Sub findFiles
    found.Initialize
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult(Permission As String, Result As Boolean)
    If (Permission = rp.PERMISSION_READ_EXTERNAL_STORAGE) Then
        findFiles(File.DirRootExternal, ".OXS", found)
    End If
End Sub

Sub findFiles(path As String, extn As String, result As List)
    Dim files As List = File.ListFiles(path)
    If (files.IsInitialized) Then
        For Each f As String In files
            If (File.IsDirectory(path, f)) Then
                findFiles(path & "/" & f, extn, result)
            Else
                If (f.EndsWith(extn)) Then
                    result.Add(path.Replace(File.DirRootExternal, "") & "/" & f)
                End If
            End If
        Next
    End If
End Sub
This produces a list of files with the requested extension. Note that in the current form it is case sensitive.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
If you are looking for files with a particular extension then maybe you can do something like this ...
It will not work on SDCards on higher Android.
This will only work for for internal Storages. Maybe even this will not work too in future versions.
 
Upvote 0

JeffT

Member
Licensed User
It will not work on SDCards on higher Android..
Wow. Thanks for the heads up.
As a novice with Android, this sounds like more of the 'nanny state' that has afflicted iOS development.

I'll be trying FileDialog/Dialogs2 this week.
But I'm getting the impression it will need another 'list of what I found in one specific folder', rather than 'tell me where you put documents onto the device'
 
Upvote 0
Top