Android Question GetSafeDirDefaultExternal with errors

Discussion in 'Android Questions' started by Scantech, May 31, 2019.

  1. Scantech

    Scantech Well-Known Member Licensed User

    This is my first time experimenting with GetSafeDirDefaultExternal. I have a device where i can mount and eject secondary storage. With the following codes

    Code:
    Dim DirFile As String
            DirFile = rp.GetSafeDirDefaultExternal(
    "Test APP")

            
    'If no database file then create it and init it.
            If File.Exists(DirFile, "My1File.db") = False Then
                SQL1.Initialize(DirFile, 
    "My1File.db"True)
                Query = 
    "CREATE TABLE diagnosticlog (ID INTEGER PRIMARY KEY, RO TEXT, Date TEXT, FirstName TEXT, LastName TEXT, VIN TEXT, Year TEXT, Make TEXT, Model TEXT, FileName TEXT)"
                SQL1.ExecNonQuery(Query)
                
    'file is available just init it
            Else
                
    If SQL1.IsInitialized = False Then
                    SQL1.Initialize(DirFile, 
    "My1File.db"True)
                
    End If
            
    End If
    When i Mount the secondary storage it is successfuly with creating the .db file. But, when i eject the Secondary Storage it fails to create (Should create in DirInternal Correct?).

     
  2. Mahares

    Mahares Well Known Member Licensed User

    Code:
    Dim DirFile As String 
        
    If File.ExternalWritable Then    'check for external storage
            DirFile = rp.GetSafeDirDefaultExternal("TestAPP")    'I prefer not to have spaces in the folder name. You nay get away with Test APP
        Else
            DirFile = 
    File.DirInternal
        
    End If
     
    Erel, Jorge M A and Scantech like this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    I recommend using File.DirInternal unless there is a special reason to use the secondary storage.
     
  4. Scantech

    Scantech Well-Known Member Licensed User

    Clearing the Storage Data in Android Settings will delete any files created in File.DirInternal? That is why i prefer secondary storage first.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    All the app folders will be deleted. This includes rp.GetSafeDirDefaultExternal.
    I've just tried it.

    You can request the storage permission at runtime and write outside of your app folders. However this is not something that most apps should do.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice