Hello!
I have a problem with my App. It is very simple:
1- Download a Google Sheet (public).
2- Read data.
I think that my App works fine at first, but I have checked that it only read 18 rows of it. I have tried a lot of runtines, but I can not resolve the problem. In addition, I save the .csv in "File.DirInternal" so, I can not review the file because it is not available to any user. Although the first 18 rows are ok, after appears a lot of diferents symbols. I do not know if the problem is in the download process or in the read data process. When I change the File.DirInternal to File.Direxternal appears an erros (I think that may be to any permissions). Any Idea?. Thank you. I am stuck.
The Google Sheet page is public and mine:
My code:
I have a problem with my App. It is very simple:
1- Download a Google Sheet (public).
2- Read data.
I think that my App works fine at first, but I have checked that it only read 18 rows of it. I have tried a lot of runtines, but I can not resolve the problem. In addition, I save the .csv in "File.DirInternal" so, I can not review the file because it is not available to any user. Although the first 18 rows are ok, after appears a lot of diferents symbols. I do not know if the problem is in the download process or in the read data process. When I change the File.DirInternal to File.Direxternal appears an erros (I think that may be to any permissions). Any Idea?. Thank you. I am stuck.
The Google Sheet page is public and mine:
My code:
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
DownloadFile
leer
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub DownloadFile()
'download csv file
Dim j As HttpJob
j.Initialize("", Me)
j.Download2($"https://docs.google.com/spreadsheets/d/1ZXx9s0yrOPZhX3GtlQgtcG7gvP6nqT74eJqiEv5H2qo/edit?usp=sharing"$, _
Array As String("mimeType", "text/csv"))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "datos.csv", False)
File.Copy2(j.GetInputStream, out)
out.Close '<------ very important
End If
j.Release
End Sub
Sub leer
Log("=======LEER =====")
Dim Reader As TextReader
Dim S As String
Reader.Initialize(File.OpenInput(File.DirInternal, "datos.csv"))
S = Reader.ReadAll
Reader.Close
Log("===========")
Log(S)
End Sub