Android Question Export the text file after save it (B4X TextEditor example)

asales

Expert
Licensed User
Longtime User
I'm using this example:
and I want to export the text file using intent, after save it.

How can I get the path of the saved file and open an intent to share it?
B4X:
Wait For (FileHandler1.SaveAs(in, "text/plain", "NewFile.txt")) Complete (Success As Boolean)
If Success Then
    < INTENT TO SHARED THE FILE ?? >  '<- Here
End If

Thanks in advance for any tip.
 

Mahares

Expert
Licensed User
Longtime User
I want to export the text file using intent, after save it.
Here is how I did it, it works, but I am not sure it is a good approach. Let's hope Erel can make it more elegant and practical.
B4X:
Private Provider As FileProvider 'in class_globals
Provider.Initialize
If Success Then
        toast.Show("File saved successfully")        
        wait for (CreateFileToSend) Complete (Res As Object)    
    Else
        toast.Show("File not saved")
    End If
    
    Dim email As Email
    email.To.Add("asales@spain.europe")
    email.Subject = "Spain"
    email.body = "Useful information promised"
    email.Attachments.Add(Provider.GetFileUri("asales.txt"))
    Dim Myin As Intent = email.GetIntent
    Myin.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
    StartActivity(Myin)   
End Sub

Sub CreateFileToSend As ResumableSub    
    Dim b() As Byte = txtField.Text.GetBytes("UTF8")
    Dim Inps As InputStream
    Inps.InitializeFromBytesArray(b, 0, b.Length)    
    Dim out As OutputStream
    out = File.OpenOutput(Provider.SharedFolder,  "asales.txt", False)
    File.Copy2(Inps,  out)
    out.Close
    Return Null
End Sub
 
Upvote 0
Top