Android Question File.DirRootExternal become not work

Khairy Abdelhamid

Licensed User
Dear Alls;

From very long time, I use File.DirRootExternal without any problem.
Now, I try to compile one of my project with same compile version but not work. It is abnormal.
Even some function work like:
File.Exists(File.DirRootExternal ,"abc.sqlite") = True work will
SQL1.Initialize(File.DirRootExternal ,"abc.sqlite",True) not work and even not create file if i delete previous file.

What happened with the compiler to make DirRootExternal not work

I Added the following permissions in the Manifest file, but still DirRootExternal not work

Please i hope to find, first what happened with the project ?
and how can I solve to make DirRootExternal work right again with all function (like SQL.Ini...)

Thanks in advance,
Best regards

Khairy Abdelhamid

Licensed User
Dear Mr. Jeffrey

Really many thanks for your interest.

I try with "GetSafeDirDefaultExternal" as in the link you sent

It access the following link :
" /storage/emulated/0/Android/data/com.test.ext.dir/files " where com.test.ext.dir is the project package name,

But I need to access root directory i.e. /storage/emulated/0/

I need to make two different application access same directory/files but in the above result the two applications will access different directly based on its package name

note: if you create two different application to run on same mobile, them must take two different package names.

Hope for find solution to access the main root of mobile i.e. /storage/emulated/0/

best regards


Well-Known Member
Licensed User
FWIW I just tried this and it seemed to work ok. Phone is running Android 7.0, B4A is 9.00, targetSdkVersion is 26 (ie unchanged default)
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

    Dim PermissionsGoodFlag As Boolean = True
    If PermissionsGoodFlag Then
        Wait For Activity_PermissionResult (Permission As String, YaeOrNay As Boolean)
        If YaeOrNay = False Then
            PermissionsGoodFlag = False
        End If
    End If
    If PermissionsGoodFlag Then
        Wait For Activity_PermissionResult (Permission As String, YaeOrNay As Boolean)
        If YaeOrNay = False Then
            PermissionsGoodFlag = False
        End If
    End If
    Log("PermissionsGoodFlag = " & PermissionsGoodFlag)
    If PermissionsGoodFlag Then
        File.WriteString(File.DirRootExternal, "1.txt", "This is the file in the root external directory")
        File.MakeDir(File.DirRootExternal, "khab")
        Dim KhabDir As String = File.DirRootExternal & "/khab"
        File.WriteString(KhabDir, "2.txt", "This is the file in Khab's directory")
        Dim D As String = File.DirRootExternal
        Log("Dir = " & D)    
        Log("ReadString = " & File.ReadString(D, "1.txt"))
        Dim D As String = KhabDir
        Log("Dir = " & D)
        Log("ReadString = " & File.ReadString(D, "2.txt"))
    End If
End Sub
Project, Manifest Editor has two lines added at bottom:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
Log is:
Logger connected to:  TCL 5009A
--------- beginning of main
*** Service (starter) Create ***
--------- beginning of system
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
** Activity (main) Resume **
PermissionsGoodFlag = true
Dir = /storage/emulated/0
ReadString = This is the file in the root external directory
Dir = /storage/emulated/0/khab
ReadString = This is the file in Khab's directory
** Activity (main) Pause, UserClosed = false **
Tools, B4A Bridge, File Explorer is:


(don't worry about the [1]'s in the file window title bars - that's just Windows letting you know that I did the procedure twice, to be sure, to be sure... ;-)


Well-Known Member
Licensed User
it run with your code
I had two gut reactions to this:

1/ what?!?! did you have doubt that it would ?!?!?!
2/ phew! (because, with computers being computers and Android being Android, it so easily might not have)


ps thanks for the feedback confirming it worked - that'll give hope to other people who read this thread in the future when they are trying to solve the same or similar issue