Android Question load to application start application .csv file

fgh3966

Active Member
Licensed User
Hello Everybody

I want to load a file for example csv file, that are into the directory Téléchargement and use it as if it had been supported by this sub.

B4X:
Private Sub HandleLoadResult(Result As LoadResult)
    If Result.Success Then
        Try
            Dim Reader As TextReader
            Reader.Initialize(File.OpenInput(Result.Dir, Result.FileName))
'             Dim line As String
            line = Reader.ReadLine
'            stringList.Add(line)
            Do While line <> Null
                line = Reader.ReadLine
                stringList.Add(line)
                increm = increm +1        ' nombre lignes dans le CSV
            Loop
            Reader.Close
    '        chainetexte = File.ReadString(Result.Dir, Result.FileName)
            toast.Show($"File '${Result.RealName}' loaded"$)
        Catch
            chainetexte = "Error loading file"
            'Log(LastException)
        End Try
    End If
'    LoadGTR2
    Log ("nbre lignes  "&increm)
'    txtField.Text = chainetexte   
End Sub

It is possible ?

Thanks.
 

Attachments

  • csvBase.zip
    13.8 KB · Views: 40

fgh3966

Active Member
Licensed User
Hello all

Excuse my bad English

The process around Reader is difficult to understand.
When starting application, Reader should load with a csv file and the file name and path would be indicated by variables.
I think that i need two variables : One for the path and another for the file name.

I wrote the code below: it is executed but Reader did not load the csv file

B4X:
Private Sub HandleGO '(Result) ' As LoadResult)
Dim ffile, ppath As String
ppath = "Download"
ffile = "file2023.csv"

        Try
            Dim Reader As TextReader
            Reader.Initialize(File.OpenInput(ppath, ffile))
            
            etc ...

End Sub

Any help please ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

fgh3966

Active Member
Licensed User
in red color debugger say >>> Caused by: java.io.FileNotFoundException: Download/file2023.csv (No such file or directory)
It's android 8.01
How to know path into android with b4a ? I think the ls -l command is not working?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
in red color debugger say >>> Caused by: java.io.FileNotFoundException: Download/file2023.csv (No such file or directory)
It's android 8.01
How to know path into android with b4a ? I think the ls -l command is not working?
Why do you use the Download directory? do you know its absolute path? where is the file2023.csv from?
 
Upvote 0

fgh3966

Active Member
Licensed User
I use the Download folder because it seems simple for users, maybe the documents folder?
If you recommend other places I'm willing to try.
I would like to code an app that is easy to use and if possible not too complicated to program .

file2023.csv are into download directory
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I use the Download folder because it seems simple for users, maybe the documents folder?
If you recommend other places I'm willing to try.
I would like to code an app that is easy to use and if possible not too complicated to program .

file2023.csv are into download directory
Where is the file2023.csv from, third App? see your post#1, you are using contentchooser to get file, the directory is contentDir
 
Last edited:
Upvote 0

fgh3966

Active Member
Licensed User
I use using contentchooser to get file because this function are coded into an example (I don't really understand how it works)
New i want to load a csv file into Reader object or variable by specifying the path and name of the csv file

file2023.csv file are into Download directory
 
Upvote 0

teddybear

Well-Known Member
Licensed User
both are available in the ContentChooser Result event.

B4X:
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)

You can use Dir and Filename in this Event
The example in post #1 it can read text file using CC, I don't know why to read file2023.csv by specified Download path in Post #3? so I asked where the file2023.csv is from.
 
Upvote 0

fgh3966

Active Member
Licensed User
Into filehandler i copy and rename Load As ResumableSub and disable cc.Show("text/*", "Choose text file")

B4X:
Public Sub StartLoad As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
'    cc.Show("text/*", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub

Public Sub Load As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/*", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub

and into B4Xmainpage i copy btnload_clik sub

B4X:
Private Sub BtnLoad_Click 
    #if B4A
    Wait For (FileHandler1.Load) Complete (Result As LoadResult)
    #else if B4i
    Wait For (FileHandler1.Load(Me, B4XPages.GetNativeParent(Me).TopRightButtons.Get(1))) Complete (Result As LoadResult)
    #end if
    'txtField.textfield.enabled = True
    HandleLoadResult(Result)
End Sub

private Sub StartBtnLoad 
    #if B4A
    Wait For (FileHandler1.StartLoad) Complete (Result As LoadResult)
    #else if B4i
    Wait For (FileHandler1.Load(Me, B4XPages.GetNativeParent(Me).TopRightButtons.Get(1))) Complete (Result As LoadResult)
    #end if
    'txtField.textfield.enabled = True
    HandleLoadResult(Result)
End Sub

Now I have to pass variables between sub and classes.
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
Into filehandler i copy and rename Load As ResumableSub and disable cc.Show("text/*", "Choose text file")

B4X:
Public Sub StartLoad As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
'    cc.Show("text/*", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub

Public Sub Load As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/*", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub

and into B4Xmainpage i copy btnload_clik sub

B4X:
Private Sub BtnLoad_Click
    #if B4A
    Wait For (FileHandler1.Load) Complete (Result As LoadResult)
    #else if B4i
    Wait For (FileHandler1.Load(Me, B4XPages.GetNativeParent(Me).TopRightButtons.Get(1))) Complete (Result As LoadResult)
    #end if
    'txtField.textfield.enabled = True
    HandleLoadResult(Result)
End Sub

private Sub StartBtnLoad
    #if B4A
    Wait For (FileHandler1.StartLoad) Complete (Result As LoadResult)
    #else if B4i
    Wait For (FileHandler1.Load(Me, B4XPages.GetNativeParent(Me).TopRightButtons.Get(1))) Complete (Result As LoadResult)
    #end if
    'txtField.textfield.enabled = True
    HandleLoadResult(Result)
End Sub

Now I have to pass variables between sub and classes.
You disabled the cc.Show, CC_Result event would not be fired.
 
Upvote 0

fgh3966

Active Member
Licensed User
Hello
Thank Teddybear, but when cc.Show("text/*", "Choose text file") are enabled, file2023.csv are just visible in a windows and not loaded.

Can be integrate the following code in filehandler sub ?


B4X:
Sub loaddefault(result As LoadResult)
    Dim su As StringUtils

    result = su.LoadCSV(File.DirInternal & "/documents", "file2023x.csv", ",")
   
'    Result = su.LoadCSV(File.DirInternal & "/Téléchargements"file2023x.csv", ",")
    HandleLoadResult(result)
End Sub
 
Upvote 0

fgh3966

Active Member
Licensed User
Hi
I want compile Gallery Chooser.zip to understand path, browsing androïd, etc ... however iJK_MaterialToast library is missing, where can I find it please because I don't have telegram.

Thanks
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Hello
Thank Teddybear, but when cc.Show("text/*", "Choose text file") are enabled, file2023.csv are just visible in a windows and not loaded.

Can be integrate the following code in filehandler sub ?


B4X:
Sub loaddefault(result As LoadResult)
    Dim su As StringUtils

    result = su.LoadCSV(File.DirInternal & "/documents", "file2023x.csv", ",")
  
'    Result = su.LoadCSV(File.DirInternal & "/Téléchargements"file2023x.csv", ",")
    HandleLoadResult(result)
End Sub

I really don't quite understand where file2023x.csv is from, is it shared by third app or does your app download?

Hi
I want compile Gallery Chooser.zip to understand path, browsing androïd, etc ... however iJK_MaterialToast library is missing, where can I find it please because I don't have telegram.

Thanks
Regarding this issue you'd better create a new thread to ask.
 
Upvote 0

fgh3966

Active Member
Licensed User
Hello all

I try this code because old code had many problems

B4X:
into handleloadresult
public Sub loaddefault As ResumableSub
    Log ("essai")
    Dim su As StringUtils
    Dim res As LoadResult ' = CreateLoadResult(Success, Dir, FileName)
    res = su.LoadCSV(File.DirInternal & "", "file2023x.csv", ",")
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res   
End Sub

in B4Xmainpage i call it with
B4X:
Private Sub Loaddefault
    #if B4A
    Wait For (FileHandler1.Loaddefault) Complete (Result As LoadResult)
    #else if B4i
    Wait For (FileHandler1.Load(Me, B4XPages.GetNativeParent(Me).TopRightButtons.Get(1))) Complete (Result As LoadResult)
    #end if
    HandleLoadResult(Result)
End Sub


I did several tests and obtain : java.io.FileNotFoundException: /data/user/0/b4a.example/files/file2023x.csv (No such file or directory)
'log are correct)
Of course I manually copied file2023x.csv into the /files directory
Into my phone android 8.01 i don't see part of folder /data/user/0/
Maybe android created these directories?
What do you think?
Thanks in advance.
 
Upvote 0

fgh3966

Active Member
Licensed User
Bonsoir

I'm not found help about contentchooser at start App, i want to load a csv at startup of a app, I didn't understand yours answers ☹️
It try other method as a externalstorage and edit manifest editor with android api (26) but contentchooser are the best way.
Can you help me please ?
 

Attachments

  • HlpCcRunAtStartApp.zip
    13.9 KB · Views: 12
Upvote 0

fgh3966

Active Member
Licensed User
donmanfred say You can use Dir and Filename in this Event

Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)

how can i replace Dir to file.dirasset ? and FileName by file2023.csv
am i stupid


as code : Type LoadResult (Success As Boolean, Dir As String, FileName As String, RealName As String, Size As Long, Modified As Long, MimeType As String)

(google traduct)
I used B4A's filemanager to include file.csv (no matter the name of the file) directly in my program, that way it's easier for me to know where it is in the path.
There is a type LoadResult variable composed of several variables, I must specify two of these variables to the cc=>contentchooser function so that it memorizes file.csv (well whatever the name) in the dirassets directory (because the other solutions are complicated), and this when starting the application that I would like to compile, is this possible?
Can you help me please ?

j'ai utilisé filemanager de B4A pour inclure le_fichier.csv (peu importe le nom du fichier) directement dans mon programme, comme ça il m'est plus facile de savoir où il se trouve dans le chemin.
il y a une variable type LoadResult composé de plusieurs variables, je dois spécifier deux de ces variables à la fonction cc=>contentchooser afin qu'il mémorise file2023.csv ( enfin peu importe le nom ) dans le répertoire dirassets (parce que les autres solutions sont compliquées), et ceci au démarrage de l'application que je voudrais compiler, est ce possible ?

pouvez vous m'aider svp ?
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
how can i replace Dir to file.dirasset ? and FileName by file2023.csv
You REALLY need to understand what is happening. I don´t think that you have understand how Contentchooser works. You even forgot that File.DirAssets is not writeable.

You can Copy the file in the contenchooser Event to File.DirInternal. Even under the filename file2023.csv if you like.

On Appstart you dont need ContentChooser. Just use the file you previously saved in DirInternal.
 
Upvote 0
Top