Android Question Issues making Dirs and File

GMan

Well-Known Member
Licensed User
Longtime User
I am using this example:

B4X:
If File.ExternalReadable = True Then
        If Not(File.Exists(File.DirDefaultExternal,"/calcul")) Then
            File.MakeDir(File.DirDefaultExternal,"calcul")
        End If
        dircalc= File.DirDefaultExternal&"/calcul"
        Dim idir As Boolean
        idir=File.IsDirectory(File.DirDefaultExternal,"calcul")
        Log("idir = " & idir)
    Else
        If Not(File.Exists(File.DirRootExternal,"/calcul")) Then
            File.MakeDir(File.DirRootExternal,"calcul")
        End If
        dircalc= File.DirRootExternal&"/calcul"
        Dim idir As Boolean
        idir=File.IsDirectory(File.DirRootExternal,"calcul")
        Log("idir = " & idir)
End if

But after running both locations dont contain the folder or files.
i am using Android 5 with a SD-Card that is bound to the internal memory
 

GMan

Well-Known Member
Licensed User
Longtime User
I have added that part in the manifest
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
<uses-permission
      android:name="android.permission.WRITE_EXTERNAL_STORAGE"
      android:maxSdkVersion="26" />
    )

This test causes NO error:

B4X:
    If File.ExternalWritable  = False Then
        Msgbox("SD-Karte Error Write !","Warning")
        Log(File.DirDefaultExternal)
        'Return
    End If

If i log the File.DirDefaultExternal the following path appears:
B4X:
/storage/emulated/0/Android/data/my.testapp.de/files
 
Last edited:
Upvote 0

Myr0n

Active Member
Licensed User
Longtime User
I ran your code in an new project without touching anything in the manifest, Android 5.1.1 and I added some logs to show the vars

B4X:
Dim dircalc As String
    If File.ExternalReadable = True Then
        If Not(File.Exists(File.DirDefaultExternal,"/calcul")) Then
            File.MakeDir(File.DirDefaultExternal,"calcul")
        End If
        dircalc= File.DirDefaultExternal&"/calcul"
        Dim idir As Boolean
        idir=File.IsDirectory(File.DirDefaultExternal,"calcul")
        Log("dircalc 1 "&dircalc)
        Log("idir1 = " & idir)
    Else
        If Not(File.Exists(File.DirRootExternal,"/calcul")) Then
            File.MakeDir(File.DirRootExternal,"calcul")
        End If
        dircalc= File.DirRootExternal&"/calcul"
        Dim idir As Boolean
        idir=File.IsDirectory(File.DirRootExternal,"calcul")
        Log("dircalc 2 "&dircalc)
        Log("idir2 = " & idir)
    End If

The log shows as :
B4X:
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
dircalc 1 /storage/emulated/0/Android/data/b4a.example/files/calcul
idir1 = true
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
--------- beginning of system
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

And the directory in b4a.example exist

I hope this help
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
Thx Erel, the rp.RuntimePermission does the trick - i made the entry in the manifest but requested not explicitly the Permission in the code
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…