Android Question Write access on external SD-Card

GuenterL

Member
Licensed User
Longtime User
Hi guys

I do have a problem with writing on an SD-Card.
In the small test program, I defined a storage directory called "GPSDir" to store a huge amount of GPS data.

B4X:
Sub Process_Globals
    Dim RP As RuntimePermissions
    Dim Writer As TextWriter
    
End Sub

Sub Globals
    Dim sp_storage As Spinner
    
    Dim GPSDir = RP.GetSafeDirDefaultExternal("GPSDir") As String

    RP.CheckAndRequest("Permission_WRITE_EXTERNAL_STORAGE")
End Sub

In the activity I filled a spinner with the two valid values:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    sp_storage.Initialize("Select Path")
    
    For Each s As String In RP.GetAllSafeDirsExternal("GPSDir")
        sp_storage.Add(s)
        Log(s)
    Next
End Sub

Possible values are:
/storage/emulated/0/Android/data/b4a.example3/files/GPSDir
/storage/sdcard1/Android/data/b4a.example3/files/GPSDir

The idea is to select , which dir will be used to store a simple file.

B4X:
Sub sp_Storage_ItemClick (Position As Int, Value As Object)
        GPSDir = Value
End Sub

Sub write_data
    If File.Exists(GPSDir, "Test.txt") = False Then
        Writer.Initialize(File.OpenOutput(GPSDir, "Test.txt", True))
        Writer.WriteLine("Textline")
        Writer.close
    End If
End Sub


Running the pogram, IT WORKED FINE to store a file into the internal memory,
but failed by using the sd-card.

Error message :
java.io.FileNotFoundException: /storage/sdcard1/Android/data/b4a.example3/files/GPSDir/Test.txt: open failed: EINVAL (Invalid argument)

I am running B4A 8.5 on Anroid7 Client.

Are there different permissions on memory and sdCard ?
Which is the correct way to select, which path will be used ?

Many thanks guenterl
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…