Android Question Makedir issue

mberthe

Member
Licensed User
Longtime User
I want to create a directory ("calcul") in DirdefaultExternal (in Actvity_Create) :
B4X:
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)

If i install on Asus K011 (androîd 4.4.2) --> idir = true

With the same code on HUAWEI ALE-L21 (andrid 6.0) --> idir =false
If i try to write in the directory dircalc i have the error :
B4X:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/mb.ncalc1/files/calcul/essaipoly.clc: open failed: ENOENT (No such file or directory)

Thanks for any help
 

Star-Dust

Expert
Licensed User
Longtime User
On some devices, you can not write to the DirDefaultExternal folder. Use DirRootExternal
 
Last edited:
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
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)
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
did you try the sample code?
if yes and still same issue then upload your project as zip so we can test it

edit: change ExternalReadable -> ExternalWritable
 
Upvote 0

johndb

Active Member
Licensed User
Longtime User
I want to create a directory ("calcul") in DirdefaultExternal (in Actvity_Create) :
B4X:
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)

If i install on Asus K011 (androîd 4.4.2) --> idir = true

With the same code on HUAWEI ALE-L21 (andrid 6.0) --> idir =false
If i try to write in the directory dircalc i have the error :
B4X:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/mb.ncalc1/files/calcul/essaipoly.clc: open failed: ENOENT (No such file or directory)

Thanks for any help
I think you are running into a permissions problem. I would suggest that review Erel's post https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/.
Look at the section "READ_EXTERNAL_STORAGE / WRITE_EXTERNAL_STORAGE" to add the manifest statements and runtime permissions code. I had the same problems and solved it by implementing Erel's solution.

Good luck,

John
 
Last edited:
Upvote 0

mberthe

Member
Licensed User
Longtime User
I think you are running into a permissions problem. I would suggest that review Erel's post https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/.
Look at the section "READ_EXTERNAL_STORAGE / WRITE_EXTERNAL_STORAGE" to add the manifest statements and runtime permissions code. I had the same problems and solved it by implementing Erel's solution.

Good luck,

John

it's works : it was a permission problem (my targetSdkVersion is 25 !)
thanks for help
Michel
 
Upvote 0
Top