I have an app that has two buttons – one for email & one for SMS. Depending on the button pressed I want to email or else SMS a certain text. I have coded the email button and it is working fine. The problem is that the dialog box that pops-up gives an option of e-mail or Messaging the text. I want to separate out the two, so that when the user presses email, only the options of email is there, and when the user presses SMS, only the option of Messaging is there.
Here is the code that I have tried.
private void sendEmail(){
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject of the message");
i.putExtra(Intent.EXTRA_TEXT , "Body of the message");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
Basically there seems to be a single intent Intent.ACTION_SEND for both emails & Messaging.
Any way to separate them out?
You can launch the Messaging application with a prepopulated message like this:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
or do something like this to just send it straightaway, without presenting the Messaging app:
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
String to use for sending email only is:
email.setType("message/rfc822");
Related
So I have an editText in an app I created, the aim of this editText is to send a piece of text information. I want the user to be able to send text information for me to use, it's kinda like when you have a "FeedBack" option and the user has to fill it with the required information needed, I want to be able to get this information somehow. Pls help, I'm still new to the mobile app development thing. :)
Use getText() on your EditText. This will return an Editable which can be casted to String if you want:
String feedback = editTextFeedback.getText().toString();
If you want to receive the input by mail:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try { startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
What you can do is opening a "share" activity and send the text through any app you have in the phone (whatsapp, telegram, mail, etc).
public void share(message: String) {
try {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Sending message");
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
Intent.createChooser(shareIntent, "Share with");
} catch (Exception e) {
e.printStackTrace()
}
}
This will open a window like this:
I have an POS app and I want to send my e-receipt to customers via email.
I have checked some resources and what I have found is how to send emails with text messages.
How can I make my email to look something like this?
You can pass Spanned text in your extra
final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<small><p>More content</p></small>")
.toString())
);
I think you can send email via Intent action
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{"support#tutlane.com"});
it.putExtra(Intent.EXTRA_SUBJECT, "Welcome to Tutlane");
it.putExtra(Intent.EXTRA_TEXT, "Hi Guest, Welcome to Tutlane Tutorial Site");
it.setType("message/rfc822");
https://www.tutlane.com/tutorial/android/android-send-email-with-examples
You can try the following way.
String[] recipients = {"abc#gmail.com"};
Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
// prompts email clients only
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, recipients);
email.putExtra(Intent.EXTRA_SUBJECT, "email subject");
email.putExtra(Intent.EXTRA_TEXT, "Hello, This is a test message");
try {
// the user can choose the email client
startActivity(Intent.createChooser(email, "Choose an email client from..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "No email client installed.",
Toast.LENGTH_LONG).show();
}
}
Android provides some further fields, these fields have to be attached to the Intent as extra data:
EXTRA_BCC: email addresses for blind carbon copy
EXTRA_CC: email addresses for carbon copy
EXTRA_HTML_TEXT: supply an alternative to EXTRA_TEXT as HTML formatted text
EXTRA_STREAM: URI holding a stream of data supplying the data that
are sent
EXTRA_TITLE: the title that is shown when the user has to choose an
email client
For a complete example, see this tutorial.
I want to use Intent to send an email without any touching in the screen. I tried the bellow code but it requires to choose many steps: such as email client, send button...I do not want to perform these steps. Just auto send without any touching in the screen. Is it possible in Android M? Thanks
//Email
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"abc#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Title");
i.putExtra(Intent.EXTRA_TEXT , "Body");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
using Intent with ACTION_SEND should open all Apps that can handle sending emails and user will have to select one of them to proceed with sending.
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:user_name#provider"));
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT,"Body");
try {
startActivity(Intent.createChooser(intent, "Send Email"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
but if want to send email without using other apps (email clients), you should search for how to send emails directly or check this
I am developing an app that send programatically an email, Im using stoxk LG mail
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{XXXXXXX});
i.putExtra(Intent.EXTRA_SUBJECT, "XXXXXXXXXX");
i.putExtra(Intent.EXTRA_TEXT , (" XXXXXXXX"));
try {
startActivity(Intent.createChooser(i, "Sending mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast toast = Toast.makeText(getApplicationContext(), "Not found ", Toast.LENGTH_LONG);
toast.show();
finish();
}
It opens the LG mail and pastes the SUBJECT, the TEXT and the MAIL BUT it doesn't send it , how can I achieve it?
Anny suggestion will be apreciated!
With intent you can't do this.
But look at the link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)
I am developing an android application that can send email. This following code lets me send email from my default gmail app on android device. I was wondering what the classes i should set so that i can send email from default android mail application?
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "abc#gmail.com" });
sendIntent.setData(Uri.parse("abc#gmail.com"));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "enter subject");
sendIntent.setType("plain/text");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Insert text");
startActivity(sendIntent);
You don't have to. I am using following to send an email with default mail service.
Uri uri = Uri.parse("mailto:info#yourcompany.com");
Intent myActivity2 = new Intent(Intent.ACTION_SENDTO, uri);
myActivity2.putExtra(Intent.EXTRA_SUBJECT,
"Customer comments/questions");
startActivity(myActivity2);