Android Code Snippet Correct Intent to compose an email on Android

I had to add an "Send feedback" an my app, there are lots of examples in the forum to do this, but, all of them are wrong.

The main problem is that they dont create a TRUE email intent, so, many other apps (NO mail clients) are shown on the IntentChooser, like Google drive, Telegram, etc.


Its is bad if you put a "Send email" button aon your app and the user is taken to his Google Drive.


Wrong Code:
B4X:
    Dim Message As Email
    Dim intent1 As Intent
    Message.To.Add("example@outlook.com")
    Message.Subject = "Feedback" 
    intent1 = Message.GetIntent
    StartActivity(intent1)

Incorrect.jpg





Correct Code:
B4X:
    Dim intent1 As Intent
    intent1.Initialize("android.intent.action.SENDTO", "mailto:example@outlook.com")
    intent1.putExtra("android.intent.extra.SUBJECT", "This is the subject")
    intent1.putExtra("android.intent.extra.TEXT", "This is the message body")
    intent1.WrapAsIntentChooser("Send feedback")
    StartActivity(intent1)

Correct.jpg


Using this metod, will show only mail apps in the IntentChooser.



Please like it this was helpfull to you
 
Last edited:

GaNdAlF89

Active Member
Licensed User
Longtime User
Hi, there is a way to send a mail in background mode (without select the mail app)? Thanks
 
Top