Hi,
After reading this post : https://www.b4x.com/android/forum/t...list-of-other-related-methods.129897/#content
I am trying the "saveAs" code to write text into a file
and to use it :
This code compiles without issue and runs. I can choose the file name, I can see the created file into the "download" folder.
But when I open the file it is empty, totally empty... the "test" string doesn' appear.
What am I doing wrong ?
BTW I just would like to export a serie of values acquired by my ESP32 to play with them into Excel on my PC. Everything works but the file export !
Thanks
JP
After reading this post : https://www.b4x.com/android/forum/t...list-of-other-related-methods.129897/#content
I am trying the "saveAs" code to write text into a file
B4X:
Sub SaveAs (Source As InputStream, MimeType As String, Title As String) As ResumableSub
Dim intent As Intent
intent.Initialize("android.intent.action.CREATE_DOCUMENT", "")
intent.AddCategory("android.intent.category.OPENABLE")
intent.PutExtra("android.intent.extra.TITLE", Title)
intent.SetType(MimeType)
StartActivityForResult(intent)
Wait For ion_Event (MethodName As String, Args() As Object)
If -1 = Args(0) Then 'resultCode = RESULT_OK
Dim result As Intent = Args(1)
Dim jo As JavaObject = result
Dim ctxt As JavaObject
Dim ContentResolver As JavaObject = ctxt.InitializeContext.RunMethodJO("getContentResolver", Null)
Dim out As OutputStream = ContentResolver.RunMethod("openOutputStream", Array(jo.RunMethod("getData", Null), "wt")) 'wt = Write+Trim
File.Copy2(Source, out)
out.Close
Return True
End If
Return False
End Sub
Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array(ion, i))
End Sub
Sub GetBA As Object
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetField("processBA")
End Sub
and to use it :
B4X:
Private Sub Export_click
File.WriteString(File.DirInternal, "test.txt", "test") 'just for the example.
Wait For (SaveAs(File.OpenInput(File.DirInternal, "test.txt"), "application/octet-stream", "test.txt")) Complete (Success As Boolean)
Log("File saved successfully? " & Success)
End Sub
This code compiles without issue and runs. I can choose the file name, I can see the created file into the "download" folder.
But when I open the file it is empty, totally empty... the "test" string doesn' appear.
What am I doing wrong ?
BTW I just would like to export a serie of values acquired by my ESP32 to play with them into Excel on my PC. Everything works but the file export !
Thanks
JP