Android Question Question re targetSdkVersion = "26" and email intent

GEoffT

Member
Licensed User
Longtime User
I think I have understood permissions and used them for LOCATION and WRITE EXTERNAL, etc.

I am not sure why the code below works with Sdkversion 23 but not 26. Which permission do I need to request in order for the app to send emails?

B4X:
Sub SendEmail (SendTo As String, SendBody As String, SendSub As String, SendAtt As String)
    Dim FinalEmailIntent As Intent, sPackageName As String
    LogColor("Send Att: "&SendAtt,Colors.Red)

    If SendAtt = "" Then ' Use new method - will not work with attachments
        File.Copy(path1, GlobFileName, Starter.shared, GlobFileName)
 
        FinalEmailIntent.Initialize("android.intent.action.SENDTO", "mailto:" & SendTo)
        FinalEmailIntent.putExtra("android.intent.extra.SUBJECT", SendSub)
        FinalEmailIntent.putExtra("android.intent.extra.TEXT", SendBody)
        FinalEmailIntent.PutExtra("android.intent.extra.STREAM",  CreateFileProviderUri(Starter.shared, GlobFileName))
        FinalEmailIntent.Flags = 1
        FinalEmailIntent.WrapAsIntentChooser("Send E-mail")
    Else ' Make our own list of email apps
        sPackageName = GetEmailPackage
        If sPackageName = "/cancel/" Then Return
        If sPackageName = "" Then
            Msgbox ("Unable to send email.", "")
            Return
        End If
        
        Dim MyEmail As Email
        MyEmail.To.Add (SendTo)
        MyEmail.Body = SendBody
        MyEmail.Subject = SendSub
        MyEmail.Attachments.Add(SendAtt)

    
        FinalEmailIntent = MyEmail.GetIntent
        FinalEmailIntent.SetType("text/plain")
        FinalEmailIntent.SetComponent (sPackageName)
    End If

    StartActivity (FinalEmailIntent)

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
What kisoft meant is that you need to check the list of permissions and find the ones marked as dangerous permissions. Watch the runtime permissions video tutorial for more information.

I am not sure why the code below works with Sdkversion 23 but not 26. Which permission do I need to request in order for the app to send emails?
You need to post the error message.
 
Upvote 0

GEoffT

Member
Licensed User
Longtime User
What kisoft meant is that you need to check the list of permissions and find the ones marked as dangerous permissions. Watch the runtime permissions video tutorial for more information.


You need to post the error message.
Error message is

(FileUriExposedException) android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/net.tittensor.ToxToolbox/files/shared/ScoreSheet.pdf exposed beyond app through ClipData.Item.getUri()
 
Upvote 0
Top