Android Question Write access on external SD-Card

Discussion in 'Android Questions' started by GuenterL, Feb 9, 2019.

  1. GuenterL

    GuenterL Member Licensed 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.

    Code:
    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:

    Code:
    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.

    Code:
    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
     
  2. DonManfred

    DonManfred Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice