Android Question External Storage Error not initialized

Guenter Becker

Active Member
Licensed User
Hi,
I am working with the Lib ExternalStorage.
Codeexample:
'In Activity_Create:
    
    Activity.LoadLayout("MainPage")
    If FirstTime Then
        storage.Initialize (Me, "Storage")
        FoldersStack.Initialize
        UpItem.Initialize
    End If
    
    Private Sub CopyDBExternalToInternal (DBName As String)
    Try
        '# initialize storage by selecting base folder
        storage.SelectDir(False)
        wait for storage_externalfolderavailable
        
        ' find folder
        Dim parentfolder As ExternalFile = storage.FindDirOrCreate(storage.Root,"TechDoc")
        Dim sourcefolder As ExternalFile = storage.FindDirOrCreate(parentfolder,"TDDBNavBackup")

As you may see in the code the storage Object is initialized but if I am going to use it in the shown sub I can only work well if I am starting a storage.select(True/False) followed by the wait For... .
If I don't do that storage.root will cause an Object not initialized Error.

Question:
In my case It is not neccessary that the user has to pick a folder because the needed folder is fixed to storage.root an known. How can I avoid to use the above action with the user selection to get storage.root initialized.

Hope I made myself clear. Thank you for the answer.
 

ac9ts

Active Member
Licensed User
Longtime User
The user still needs to select the top-level folder to set the permissions.

B4X:
    If FirstTime Then
        MES.Initialize(Me, "MES")
        Storage.Initialize(Me, "storage")
    End If

    ' Get access to the SDCard
   
    If Not(MES.HasPermission) Then
        MsgboxAsync("This app requires access to all files, please enable the option", "Manage All Files")
        Wait For Msgbox_Result(Res As Int)

        MES.GetPermission
        Wait For MES_StorageAvailable
    End If

    ' Get access to the SDCard directory
   
    Storage.SelectDir(True)
    Wait For Storage_ExternalFolderAvailable

    RootDir = Utils.Get_URI_Dir(File.GetText(File.DirInternal,"PersistantUri"))
    Log("Using " & RootDir)

Edit: See for a more complete description
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…