Android Question Make Folders without Erros

Douglas Farias

Expert
Licensed User
Longtime User
Hi all!
i made this code to create a folder where i go save my db sqlite.
i m making this question to only know if this is the best method to make a folder without erros on devices.

this code will works on all devices?
if no what i need to make to work?

Manifest
android.permission.WRITE_MEDIA_STORAGE


Create firsttime
B4X:
    If File.ExternalWritable Then
        If File.Exists(File.DirRootExternal, "click" ) = False Then '
            File.MakeDir(File.DirRootExternal, "click")            ' DIRROOT = CARTAO SD
              fp = File.Combine(File.DirRootExternal,"click")        '
        Else
            File.MakeDir(File.DirDefaultExternal, "click")          '
            fp = File.Combine(File.DirDefaultExternal,"click")      ' DEFAULT EXTERNAL = CARTAO SD
        End If                                                        '
    Else
        If File.Exists(File.DirInternal, "click" ) = False Then '
            File.MakeDir(File.DirInternal, "click")            ' INTERNAL = MEMORIA INTERNA DO TELEFONE
              fp = File.Combine(File.DirInternal,"click")        '
        Else
            File.MakeDir(File.DirInternalCache, "click")          '
            fp = File.Combine(File.DirInternalCache,"click")      ' CACHE = CACHE INTERNO DO TELEFONE
        End If   
    End If
 

Douglas Farias

Expert
Licensed User
Longtime User
i m want use this on the all apps on the activity create, i need to save my sqlite db but i need this working on all devices with android, if cant save on the root save on the internal and etc etc...
what code can i use to save a files on the all devices (All Android Versions) without erros?
i go use on the main activity create.

I dont find any good example working on the forum.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
but this go works on all devices with android @Erel ?
any try and catch?

and if the folder already existe dont go create this again?
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
B4X:
If File.ExternalWritable Then fp = File.DirDefaultExternal Else fp = File.DirInternal
    If File.IsDirectory(fp, "click") Then
        fp = File.Combine(fp,"click")
    Else
        File.MakeDir(fp, "click")
        fp = File.Combine(fp,"click")
    End If

this is correct?
 
Upvote 0
Top