Android Question How i can create csv file and attach by gmail app?

Raffaele

New Member
Hi, i need to create a file csv and attach in new email (gmail).

i have this code...but i have an error:
The file is empty...

where i wrong?

Dim su As StringUtils
Dim Rows As List
Rows.Initialize
Rows.Add (Array As String("A"))
Rows.Add (Array As String("AA"))
su.SaveCSV(File.DirRootExternal, "1.csv", ",", Rows)

Dim i As Intent
i.Initialize(i.ACTION_SEND, "")
i.SetType("text/plain")
i.PutExtra("android.intent.extra.SUBJECT", "The Subject")
i.PutExtra("android.intent.extra.TEXT", "The Body")
i.SetType("text/plain")
i.PutExtra("android.intent.extra.STREAM", CreateUri("file://" & File.Combine(File.DirDefaultExternal, "1.csv")))
StartActivity(i)
 

Didier9

Well-Known Member
Licensed User
Longtime User
Try this:

B4X:
    Private ei As Email ' requires Phone library    
    Try
        ei.To.Add( email )
        ei.Body = "File is attached."
        ei.Subject = "FileName.txt"
        ei.Attachments.Add( File.Combine( FilePath, FileName ))
        StartActivity( ei.GetIntent )
    Catch
        ToastMessageShow( "No mail apps", True )
    End Try
 
Upvote 0

Raffaele

New Member
I try it...


'''''''create the file csv'''''''''

Dim su As StringUtils
Dim Rows As List
Rows.Initialize
Rows.Add (Array As String("A"))
Rows.Add (Array As String("AA"))
su.SaveCSV(File.DirRootExternal, "1.csv", ",", Rows)

''''''''''''''' end '''''''''''
'''''''' send mail ''''''''''
Private ei As Email ' requires Phone library
Try
ei.To.Add("mymail@gmail.com")
ei.Body = "File is attached."
ei.Subject = "FileName.txt"
ei.Attachments.Add( File.Combine(File.DirDefaultExternal, "1.csv"))
StartActivity( ei.GetIntent )
Catch
ToastMessageShow( "No mail apps", True )
End Try
''''''''''''''''' end '''''''''''''''''

but i receive in the gmail app this message :"Impossible to attach the empty file"...
...but my file is not empty.
Any ideas?Thank you for support.
 
Upvote 0

Raffaele

New Member
Sorry ...
i solved it...
i messed up..
i chane this line
ei.Attachments.Add( File.Combine(File.DirDefaultExternal, "1.csv"))
with this...
ei.Attachments.Add(File.Combine(File.DirRootExternal, "1.csv"))

Now work.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Sorry ...
i solved it...
i messed up..
i chane this line
ei.Attachments.Add( File.Combine(File.DirDefaultExternal, "1.csv"))
with this...
ei.Attachments.Add(File.Combine(File.DirRootExternal, "1.csv"))

Now work.

Yes, the error message is misleading. GMail should say it cannot find the file rather than say it was an empty file.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…