Displaying the To address prefilled in Email Intent?
Asked Answered
A

5

14

enter image description hereI am not able to pre fill the TO field in Email client to the "to" address mentioned in the extras here:

EmailImage.setOnClickListener(new OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                 // TODO Auto-generated method stub  
                Intent it = new Intent(Intent.ACTION_SEND_MULTIPLE);   
                it.putExtra(Intent.EXTRA_EMAIL, "[email protected]");   
                it.putExtra(Intent.EXTRA_SUBJECT, "Regarding Policy Info");  
                it.putExtra(Intent.EXTRA_TEXT, "When is my next Premium due");  
                //it.setType("text/plain");   
                it.setType("message/rfc822");  
                startActivity(it);   
            }  
        });  

What is the problem?

Thanks
Sneha

Agneta answered 13/2, 2012 at 11:40 Comment(1)
would you mind posting your working solution? (I'm facing the same issue, but I do have put the address in an array already...still empty "TO field")Fultz
U
43

You need to put the address in an array:

it.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"});

See here.

Ulrikeulster answered 13/2, 2012 at 11:42 Comment(5)
what did it take to work now for you? (assuming that u provided a string array for recipient before?). maybe u can post the final working sample code!? thx.Fultz
@Fultz Didn't understand the question.Ulrikeulster
My question was targeted @sneha, whether he could post his working solution. (I have the same problem, although I put the address in an array)Fultz
@Fultz - so post the comment under his question, so he will be notified.Ulrikeulster
sry, my bad. thought he's notified since he has accepted this as the solution.Fultz
H
7

I've got something like this and its works:

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("plain/text");
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
            intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
            intent.putExtra(Intent.EXTRA_TEXT, "mail body");
            startActivity(Intent.createChooser(intent, ""));
Helluva answered 13/2, 2012 at 11:43 Comment(1)
experiencing the same problems (using your exact same code above); TO filed just remains empty :-(Fultz
C
2

When using ACTION_SEND_MULTIPLE,

You have to provide an array of String for Intent.EXTRA_EMAIL Binyamin Sharet shown you.

If the requirement is to provide only one Address then use Intent.ACTION_SEND.

Cacka answered 13/2, 2012 at 12:42 Comment(0)
E
0

Try this

Intent sendIntent = new Intent(Intent.ACTION_SEND);
                        sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"","your email"});
Eolic answered 13/2, 2012 at 12:53 Comment(0)
D
0

This worked for me:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "[email protected]" });
                        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, edt_msg.getText().toString());
                        emailIntent.putExtra(Intent.EXTRA_SUBJECT, edt_subjct.getText().toString());
                        emailIntent.setType("message/rfc822");

                        Uri uri = Uri.parse("file://" + file_img_capt);
                        emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                        startActivity(emailIntent);
Droopy answered 4/4, 2017 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.