I need to find a known file in a known folder on the external SD Card and display it in an image viewer. Ghost commander can do this apparently using both the old file:// way and also with Stoarge Access Framework.
I am trying to use the ExternalStorage class but it is not behaving as I expect and I'm puzzled. I would expect the following code to produce
Folder = Maps OS 1000K
FindFile =Lat Long UK.jpg
ListFiles =Lat Long UK.jpg
for a known file
/storage/0000-0000/Maps OS 1000K/Lat Long UK.jpg
It doesn't
What seems to be happening is that while 'extfolder' seems to have the correct name it is actually referring to a different folder, probably the next in the list and FindFile and ListFiles are looking in this folder and not the expected one. If I set filename to the name of a file in this other folder then it is found by FindFile and ListFile. Or am I being stupid?
If I could find the file I could copy it to the Download folder in DirRootExternal and open it in an image viewer from there using FileProvider which I have already tested.
I am trying to use the ExternalStorage class but it is not behaving as I expect and I'm puzzled. I would expect the following code to produce
Folder = Maps OS 1000K
FindFile =Lat Long UK.jpg
ListFiles =Lat Long UK.jpg
for a known file
/storage/0000-0000/Maps OS 1000K/Lat Long UK.jpg
It doesn't
What seems to be happening is that while 'extfolder' seems to have the correct name it is actually referring to a different folder, probably the next in the list and FindFile and ListFiles are looking in this folder and not the expected one. If I set filename to the name of a file in this other folder then it is found by FindFile and ListFile. Or am I being stupid?
B4X:
Sub btnSDCard_Click
Dim msg As String = ""
Dim extfolder As ExternalFile
Dim extfile As ExternalFile
Dim folder As String = "Maps OS 1000K"
Dim filename As String = "Lat Long UK.jpg"
Storage.SelectDir(True)
Wait For Storage_ExternalFolderAvailable
For Each f As ExternalFile In Storage.ListFiles(Storage.Root)
If f.Name = folder Then
extfolder = f
Exit
End If
Next
msg = "Folder = " & extfolder.Name & CRLF
extfile = Storage.FindFile(extfolder, filename)
msg = msg & "FindFile = " & extfile.Name & CRLF
For Each g As ExternalFile In Storage.ListFiles(extfolder)
If g.Name = filename Then
extfile = g
msg = msg & "ListFiles = " & g.Name & CRLF
End If
Next
ToastMessageShow(msg, True)
End Sub
If I could find the file I could copy it to the Download folder in DirRootExternal and open it in an image viewer from there using FileProvider which I have already tested.
Last edited: