Android Question b4a can't save files since updating to b4a 8.0?

oldmanofthesea

Member
Licensed User
since upgrading to b4a 8.0 I can't save csv files or text files to dirrootexternal like I was able to before? what am I missing?
 

MarkusR

Well-Known Member
Licensed User
Longtime User
i guess you need
android.permission.WRITE_EXTERNAL_STORAGE
permissions in manifest if u use path File.DirRootExternal

or use other path (code fragments), see erel post with wait for
B4X:
    Dim rp As RuntimePermissions
 
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) 'it create a event
 
 
    Log("PERMISSION_WRITE_EXTERNAL_STORAGE:" & rp.Check(rp.PERMISSION_WRITE_EXTERNAL_STORAGE))
     
    For Each name In rp.GetAllSafeDirsExternal("")
        Log(name)
    Next

https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/#content
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
since upgrading to b4a 8.0 I can't save csv files or text files to dirrootexternal like I was able to before? what am I missing?
It is not related to B4A v8.0. It is related to targetSdkVersion value.

If it is set to 23+ then you need to use runtime permissions. See the runtime permissions tutorial.
@MarkusR this code is not exactly correct.

Example of writing to File.DirRootExternal (which in most cases is a mistake to use):
B4X:
   rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
   Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
   If Result = False Then
       ToastMessageShow("No permission...", True)
   Else
      File.WriteString(File.DirRootExternal, "1.txt", "aaa")
   End If
 
Upvote 0
Top