Android Question How to use ExternalStorage

Xfood

Expert
Licensed User
Goodmorning everyone,
I'm trying to use this library for
Read a file in the Download folder
But I don't know how to pass the correct parameter,
I took the example from here:

Here is my code:
B4X:
Private Sub Button1_Click
    Private cNomeFileArticoli As String = "download/articoli.csv"
    Dim ReaderFileTxt As TextReader

    If File.Exists(File.DirRootExternal, cNomeFileArticoli)= True Then
        'ReaderFileTxt.Initialize(File.OpenInput(File.DirRootExternal, cNomeFileArticoli)) '  works with SDK 29 does not work with SDK 30
        
        ReaderFileTxt.Initialize(Storage.OpenInputStream(cNomeFileArticoli))   ' not correct
    End If

End Sub

when I compile it gives me this error
B4A Versione: 10.70
Analisi del Codice. (0.01s)
Java Versione: 14
Building folders structure. (0.02s)
Compilazione del codice. (0.02s)
Compilazione del codice di layouts (0.03s)
Organizzazione Librerie. (0.03s)
(AndroidX SDK)
Compiling resources (0.24s)
Linking resources (0.44s)
Compilazione del codice Java prodotto. Error
B4A line: 139
ReaderFileTxt.Initialize(Storage.OpenInputStream
src\b4a\example3\main.java:434: error: incompatible types: String cannot be converted to _externalfile
_readerfiletxt.Initialize((java.io.InputStream)(_storage._openinputstream /*anywheresoftware.b4a.objects.streams.File.InputStreamWrapper*/ ((b4a.example3.externalstorage._externalfile)(_cnomefilearticoli)).getObject()));
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Xfood

Expert
Licensed User
I also tried ContentChooser, to read a file from the Download folder, but unfortunately I can't.
I try to study better
Thank you
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Here is my code to open a CSV file using ContentChooser:
B4X:
Private Sub btnGetCSV_Click
    CC.Show("text/comma-separated-values", "CSV File")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then       
        Dim tr As TextReader
        tr.Initialize(File.OpenInput(Dir, FileName))
        Dim line As String
        line = tr.ReadLine
        Do While line <> Null
            Log(line)
            line = tr.ReadLine
        Loop
        tr.Close
    End If   
End Sub
 
Upvote 0
Top