Android Question Question about ExternalStorage

Filippo

Expert
Licensed User
Longtime User
Hi,

in my app the classe ExternalStorage is used to store files in the SD card.

This also works quite well. But now it happens that the user removes the SD card and no longer thinks about it.
Since now when saving the SD card is no longer that and of course the storage folder is also no longer present, the app crashes.

Question: how can you intercept this error best? Or how has someone already solved it?

Ciao,
Filippo
 

William Lancee

Well-Known Member
Licensed User
Longtime User
I don't know if this will help.
I use the ExternalStorage class with USB memory sticks.
If I don't insert an USB, the result of code below is zero.

B4X:
    Storage.SelectDir(True)
    Wait For Storage_ExternalFolderAvailable
   
    Log(Storage.ListFiles(Storage.Root).size)   'No stick log = 0
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see:
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Hi,

I have created a function and added in the classe "ExternalStorage", so I can easily check if the storage folder exists or not.
If the storage folder does not exist anymore, it will ask to choose a new storage folder.
According to my tests seems to work.

B4X:
Public Sub IsStorageFolderSelected As Boolean
    If PersistantUri.Length > 0 Then
        Root = DocumentFileToExternalFile(GetPickedDir(PersistantUri))
        Log("Root.Length=" & Root.Length)
    End If
    Return File.Exists(File.DirInternal, PreviousUriFileName) And (Root.Length > 0)
End Sub
End Sub
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
and how to check if sd card is mounted???
Whether the SD card is present is not so important in my case, what is important is whether the storage folder is present.
The storage folder can be on a SD card or in File.DirRootexternal.
If the storage folder is no longer present, then Root.Length = 0.
 
Upvote 0
Top