Android Question [Solved] Makedir failure

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

I can't believe I am asking this question, it should be simple. Below a piece of code in Activity Create, checks for a dir, makes dir. simple. But it is not making the dir.
After chasing my tail for a couple of hours I copied the code from another App where it is working and changed the dir name, no good.

If someone can see what I've done wrong it would be much appreciated.

Makedir not working:
        'Permission to READ/WRITE External Memory
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        '....  and then
        If Result Then     'The HepFile is copied to an external directory where it can transferred/printed etc.
            'Copy "Help" file to the "ABT" folder
            If File.exists(File.DirRootExternal&"/ABT/","") = False Then File.MakeDir(File.DirRootExternal&"/ABT/","")
            File.Copy(File.DirAssets,"helpfile.htm",File.DirRootExternal&"/ABT/","ABTHelp.htm")
        End If


The error log.

 
Last edited:

Mahares

Expert
Licensed User
Longtime User
If someone can see what I've done wrong it would be much appreciated.
Don't get rattled Roger. Your code looks good, unless you are using a B4XPages project. I tested it on a OS 8.1 device with manifest line:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>
The first thing you might want to do is uninstall and reinstall the app , then check your OS version
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
This works for me
B4X:
    ' DON'T TARGET ABOVE API 28 FOR THE TIME BEING AS WE NEED TO WORK OUT STORAGE ACCESS
    ' Need to get all the first time things done before Wait For as FirstTime is no longer set on re-entry after a wait
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) ' Implicit read capability if granted
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)   
    Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${Result}"$)   

    If Not(File.IsDirectory(File.DirRootExternal, IdeDir)) Then
        File.MakeDir(File.DirRootExternal, IdeDir)
    End If
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User

Mahares thanks for the reply.
Device Galaxy A70 Android 10. Uninstalled/installed many times.
Working my way through the replies.
Manifest:

 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
MakeDir looks wrong. It probably 'seems' to work in the other app because the folder already exists. Try:

File.MakeDir(File.DirRootExternal, "ABT")
agraham,
When I said works I meant that creating the Dir works. I have uninstalled and deleted the ABT folder, restarted the device, restarted the IDE. No success.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Sorry agraham but I get an Undeclared Variable error for IdeDir.
 
Last edited:
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User

Mahares,
Fixed it. Tested on A70 android 10 and Note 3 Android 5. That should cover most options.

Many Thanks again Mahares.

In a perfect world, "Permissions" would be transparent to the developer. If the Android System wants the user to give permission, the Android System should be requesting it.
Just my opinion of course.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…