Android Question Possible approach for "ExternalStorage-Class"

D

Deleted member 103

Guest
Hi,

I would like to implement this approach, what do you think?

The "setStorageFolder" procedure is executed before each memory access, but the user should only select the storage folder the first time.
With the check of "Starter.manager.getBoolean ("IsDirDefaultExternal")" one can then differentiate how the memory access should take place.


B4X:
Private Sub mnuShowArchiv_Click

'  Here is just an example of how to use it.  
    SelectStorageFolder(mShowStoredResults)
End Sub

Private Sub setStorageFolder(act As Object)
    If Not(ExStorage.IsStorageFolderSelected) And Not(Starter.manager.getBoolean("IsDirDefaultExternal")) Then
        Msgbox2Async("According to the latest Google guidelines, an app may only use its own folder as data storage." & CRLF & _
        "If data is to be stored outside of these folders, then the user must explicitly authorize access.", "New Google guidelines", "OK", "", "", Application.Icon, False)
        Wait For Msgbox_Result (Result As Int)

        Msgbox2Async("In the next dialog you should select or create a folder for data storage." & CRLF & _
                    "If you do dot Select dr create a folder, the default folder of the app will be set as data storage!" & CRLF & _
                    "This would have the disadvantage that all data will be deleted when uninstalling the app." & CRLF & _
                    "Do you want to Select a folder yourself?", "Select data storage", "Yes", "No", "", Application.Icon, False)
        Wait For Msgbox_Result (Result As Int)
        If Result <> DialogResponse.POSITIVE Then
            Log("Standard-Folder")
            Starter.manager.SetBoolean("IsDirDefaultExternal", True)
        End If
    End If

    If Not(Starter.manager.getBoolean("IsDirDefaultExternal")) Then
        ExStorage.SelectDir(True)
        Wait For ExStorage_ExternalFolderAvailable
        Log("External-Folder")
    End If
    
    StartActivity(act)
End Sub

The "IsStorageFolderSelected" function is an extra function that I added to the "ExternalStorage" class.
B4X:
Public Sub IsStorageFolderSelected As Boolean
    Return File.Exists(File.DirInternal, PreviousUriFileName)
End Sub
 
D

Deleted member 103

Guest
Looks fine. Do remember that there could be cases where the user needs to pick the folder again as the previous uri cannot be used (see the code in SelectDir).
If the user chooses a different folder, it is his own fault.;)
 
Upvote 0
Top