I'm launching the email program in Android from my app, using the following code...
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Test subject");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Hello World!");
startActivityForResult(Intent.createChooser(sendIntent, "Select email application."), INTENT_REQUEST_SEND_EMAIL);
In the called OnActivityResult(), is it possible to get the number of recepients the user has chosen to send the email to?
Thanks,
Rajath
That action does not support startActivityForResult(), sorry.
Related
How can I create a simple program that it can send a text to a gmail address?
I want to create a simple program that it have a EditText and when I write some text in the EditText and I click on the Button, as the result the text be sent to a gmail address, for example to the example#gmail.com. I know how to create a EditText class but I do not know the operation post to the gmail. Thank you.
In Android, you can use Intent.ACTION_SEND to call an existing email client to send an Email.
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"put_your_mail#gmail.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
For more details you visit How to send Email in Android and
http://code.tutsplus.com/tutorials/quick-tip-enabling-users-to-send-email-from-your-android-applications-the-easy-way--mobile-1686
Standard way to do this is using the ACTION_SEND intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress#emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
If you want to send the mail in background without opening another app check this answer https://stackoverflow.com/a/2033124/2761055
Here, you have information how to do that in background with PHP file on your server.
But in my opinion, this method is deprecated.
Look also here. This code will start new intent with email.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text.getText());
sendIntent.setType("message/rfc822");
startActivity(Intent.createChooser(sendIntent, "Send email with"));
this was my code.
I tried the send mail in emulator. But it shows the no application can perform this action. if anyone knows means tell me
Thanks in advance
You need to use text/plain
intent.setType("text/plain");
Also, the Intent.ACTION_SEND is made for sharing, you may want to use Intent.ACTION_SENDTO to only get the list of e-mail clients, or avoid sharing applications such as Facebook, Twitter, etc.
This worked for me
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail#yahoo.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
There's a better approach if you want to send mail: use Action.SEND_TO:
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:sample#mail.com"));
sendIntent.putExtra(Intent.EXTRA_TEXT, text.getText());
That will narrow down the searchlist.
NOTE: Make sure you have set up email account on emulator, else the Email application will not be in the handlers-list, and you'll get exception.
This means that there is no application that is registered for handling such kind of intent.
Edit:
Try setting the intent type to "text/plain"
emailIntent.setType("text/plain");
and/or set EXTRA_EMAIL to set the content of the email
sendIntent.putExtra(Intent.EXTRA_EMAIL, text.getText());
After trying everything as mentioned in the above comments, if you don't find your solution, Just set an email in the default email in Emulator. It works for me.
private fun sendMail(recipient: String, subject: String, message: String)
{
val mIntent = Intent(Intent.ACTION_SEND)
mIntent.data = Uri.parse("mailto:sample#gmail.com")
mIntent.type = "text/plain"
mIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(recipient))
mIntent.putExtra(Intent.EXTRA_SUBJECT, subject)
mIntent.putExtra(Intent.EXTRA_TEXT, message)
try {
startActivity(Intent.createChooser(mIntent, "Choose email client"))
Toast.makeText(this, "Hey !! We received your order :) ", Toast.LENGTH_LONG).show()
}catch (e:Exception){
e.printStackTrace()
Toast.makeText(this, "Sorry your order could not be sent :( ", Toast.LENGTH_LONG).show()
}
}
This code works for me, I was facing the same problem,
changing : "val mIntent = Intent(Intent.ACTION_SENDTO)" to
"val mIntent = Intent(Intent.ACTION_SEND)" solved the problem for me.
Hope my response would help the readers
This generally means that there is no application installed currently, that understands the request you're making.
In this instance I would hazard a guess that there is no email app installed on the emulator? Or possibly that it hasn't been set up.
I'm programming an Android application. I want to invoke other applications to perform certain operations(Sending emails etc.) How do I know which action and category to set for the intent? Should I look other application's intent filter? What if that application is not open source?
Also, for the data or extra attribute, I don't know how the 3rd party application will handle my intent, so I do not know how to set the attributes. For example, I want one string as the title of the email, one string as the content of the email, and another string as the recipient, and a picture as the attachment. Can I include all these information in the intent? What if the 3rd party application don't provide any functionality to handle it?
Usually, for common tasks in Android there is a general Intent that you send on which other applications can register.
for example to share some text you would create an intent like:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
will prompt android's native share dialog on which the user can choose how he wants to share it.
Specifically for email you would do something like:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","email#domain.com", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "This is my email subject");
startActivity(Intent.createChooser(intent, "Email"));
Other examples may be to launch the default sms application:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
sendIntent.putExtra("sms_body", getMessageBody());
Or open the phone's dialer:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+number));
startActivity(intent);
You need to figure out what are the actions that you want to implement in your app and then figure out how to implement each of them.
You can find some more data here:
Android content sharing
Android intents - under the various intent actions
Try using category and actions in intent.
Intent mailIntent = new Intent(Intent.ACTION_SEND);
mailIntent.setType("text/plain");
mailIntent.putExtra(Intent.EXTRA_SUBJECT, "Reporting mail");
mailIntent.putExtra(Intent.EXTRA_TEXT, "Some message");
mailIntent.putExtra(Intent.EXTRA_EMAIL, "xxx#yyy.com");
startActivity(mailIntent);
this is an example for sending email. For further details refer http://developer.android.com/guide/components/intents-common.html
Hello I am just curious about.
From Message Inbox/Outbox. we can retrieve :phone number,message body,date,locked status,StatusOnSim etc.
So Can we retrieve from email (sent+inbox):Email_id,Subject,Body,CC,BCC etc.
I want to retrive all this thing from my email like Email_id,Subject,Body,CC,BCC etc
if any one have idea regarding this than please help me on it.
Code to send email information:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {
"ur mail id" });
intent.putExtra(Intent.EXTRA_SUBJECT, "ur subject");
intent.putExtra(Intent.EXTRA_TEXT, "ur text");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(FileName));
startActivity(Intent.createChooser(intent, "Choose"));
it cant retrieve data like Email_id,Subject,Body,CC,BCC etc from ur mail box. But it possible in Message inbox.
I want to send an email with android 2.2. First I made an intent chooser with an ACTION_SEND to select which to use :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("EmailInvitationSubject", getBaseContext()));
String body = Resources.getString("EmailInvitationBody", getBaseContext()) + Local.User.FirstName;
intent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(intent, "Invite friends"));
But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. I want to show ONLY Gmail or other email app.
I saw in the sdk docs there's a new CATEGORY_APP_EMAIL to use but it's only available in the API level 15. I have to keep API level 8. Is there a way to do that ?
By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: one for email and one for messaging.
This code will shows only the email clients,
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail#yahoo.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
You might want to checkout following (to get what you are looking at the end, i.e. "....By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: "):
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android
or also you could checkout:
Android email chooser
Kind regards,
Bo