Android Question [SOLVED] Send Email with AttachFiles under SDK>23 get err FileUriExposedException

scsjc

Well-Known Member
Licensed User
Longtime User
Hi,
i send a email with this code, but in SDK>23 get error when Attach file :

android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.xxxxxx/files/share/xxxxx.jpg exposed beyond app through ClipData.Item.getUri()

B4X:
Sub sendemail(destinatario As String, subject As String, body As String, filecombineattachment As String)
            Dim Msg As Email
            Dim nt As Intent
            Msg.To.Clear ()
            Msg.To.Add(destinatario.trim)
            Msg.BCC.add(correo.trim)
            If subject.Trim <> "" Then Msg.Subject = subject.trim
            Msg.Body = body
            If filecombineattachment<>"" Then Msg.Attachments.Add(filecombineattachment)
            nt= Msg.GetIntent
            nt.SetType("message/rfc822")
            StartActivity(nt)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What is the question or the issue to answer this? I was aware that you are using targetsdk 26 (i asumed it).
You need to understand the problem. That´s the reason i posted the two links.
The first to show an overview with description and additional links.
The second link is the one relevant here. You need to use the Fileprovider on Android devices with an SDK 24 or higher.
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
What is the question or the issue to answer this? I was aware that you are using targetsdk 26 (i asumed it).
You need to understand the problem. That´s the reason i posted the two links.
The first to show an overview with description and additional links.
The second link is the one relevant here. You need to use the Fileprovider on Android devices with an SDK 24 or higher.

Yes, I'm working on updating apps to the sdk 26, and there are parts that I understand and work correctly like the one I show here, but I have not managed to work in the email :(


B4X:
Dim in As Intent
           in.Initialize(in.ACTION_VIEW, CreateFileProviderUri(Starter.tempfolder, fileload))
           in.Flags = 1
           StartActivity(in)

Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
   Dim FileProvider As JavaObject
   Dim context As JavaObject
   context.InitializeContext
   FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
   Dim f As JavaObject
   f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
   Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub
 
Upvote 0
Top