Android Question Sending emails with selected app

berndm2

Member
Licensed User
Longtime User
I would like to send an email with a special app (Gmail or Email). How must this call be programmed ( with StartActivity (FinalEmailIntent)) to specifically call the respective app directly without asking?
 

berndm2

Member
Licensed User
Longtime User
I tried the following:

FinalEmailIntent=pm.GetApplicationIntent("com.google.android.gm") 'GMAIL
FinalEmailIntent.initialize("android.intent.extra.SENDTO", "mailto:" & Mailadr)
FinalEmailIntent.putExtra("android.intent.extra.SUBJECT",Message.Subject)
FinalEmailIntent.putExtra("android.intent.extra.TEXT",Message.Body)
StartActivity (FinalEmailIntent)


However, I will always be shown a selection of email apps, not just the app: GMAIL to send the email to.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
you should not initialize the intent you got from GetApplicationIntent
 
Upvote 0

berndm2

Member
Licensed User
Longtime User
If I do not initialize the message components are not taken over (to GMAIL).
So I only have the option to call GMAIL without mail data or to transfer the mail data to them after additional selection of the mail program. It must be possible to specify a specific mail program by program and to pass the mail data to it?
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
It must be possible to specify a specific mail program by program and to pass the mail data to it?
that i meant with "u can change propertys in the Intent before use in StartActivity"
if you search for the usage of a Intent you will find examples for SetComponent and SetType.
if you not change the Intent it will ask which of the mail app you will use.

i believe at SetComponent its com.google.android.gm

Lib Phone
B4X:
    Dim M As Email
    M.Attachments.Add ...
    M.Body = " ... "
    M.Subject = "..."
    M.To = ...
    Dim I As Intent= M.GetIntent()
    I.SetComponent("...")
    I.SetType("...)"
    StartActivity(I)
 
Upvote 0

berndm2

Member
Licensed User
Longtime User
Thank you but unfortunately, the problem is not solved:
With the following

Dim In As Intent= Message.GetIntent()
In.Setcomponent("com.google.android.gm")
In.SetType("text/plain")
StartActivity(In)

I do not reach GMAIL being called.
Furthermore, only a selection of email apps will be displayed, to which the message components will then be transferred as desired.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
the nearest i can do

B4X:
Sub MailOut

    Dim p As Email
    p.Body="Inhalt"
    p.Subject="Betreff"
    p.To.Add("[email protected]")

    Dim i As Intent
    i = p.GetHtmlIntent
    i.Setcomponent("com.google.android.gm")
    i.SetType("message/rfc822")

    StartActivity(i)
  
End Sub

immer = always
Screenshot_2018-03-09-21-00-35.png
 
Upvote 0

berndm2

Member
Licensed User
Longtime User
Even with the last suggestion, I can not call GMAIL directly and pass the email data to GMAIL. In fact, a component with package name can not be successfully added. T
here is still an ad for selecting possible email applications. Probably there is no direct call solicitation with passing the data to GMAIL. Thank you for your efforts.
 
Upvote 0

berndm2

Member
Licensed User
Longtime User
I found a simple solution to directly submit my emails to the desired email app by examining all installed SENDTO actions and then launching the desired action (for example, from Gmail).


Sub Mailen

Mailapp = "com.google.android.gm" 'Packagename

Message.To.Add (Mailadr)

Message.Body = "Body"

Message.Subject = "Subject"

sPackageName = GetEmailPackage

Dim In As Intent

In = Message.GetIntent

In.SetComponent(sPackageName)

StartActivity(In)

End Sub

Sub GetEmailPackage As String

Dim pm As PackageManager

Dim Int1 As Intent

Int1.Initialize("android.intent.action.SENDTO", "mailto:[email protected]")

For Each cn As String In pm.QueryIntentActivities (Int1)

If cn.IndexOf(Mailapp) >-1 Then Exit

Next

Return cn

End Sub
 
Upvote 0
Top