Android: insert subject with autoLink="email" - android

I use a textview with android:autoLink="email" to send an email being redirected to the smartphone Email or Gmail application. It works but I can't insert a subject. Are there people coming to do ?

You could send an email this way :
String[] TO = {""};
String[] CC = {""};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
And call this in the onClick event of the TextView.
You could also put some style to show it as a clickable link (underlined, colored).
TO will then contain the value of the TextView

Related

How to Send Emails?

I found an algorithm to send an email through an Android app. When I run it, it opens a list of apps I can choose to send it, however, I only wanted to use the Gmail app.
This is the code:
protected void sendEmail(String subject, String text) {
Log.i("Send email", "");
String[] TO = {"email#gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, text);
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email!", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(), "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
Thanks in advance!
Implicit Intents declare a general action to perform, in your case every app that has an intent filter of an e-mail client, this can be Gmail, Outlook or whatever e-mail client that your device has.
In this case you can try this code:
Intent sendIntentGmail = new Intent(Intent.ACTION_VIEW);
sendIntentGmail.setType("plain/text");
sendIntentGmail.setData(Uri.parse(TextUtils.join(",", addresses)));
sendIntentGmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntentGmail.putExtra(Intent.EXTRA_EMAIL, addresses);
if (subject != null) sendIntentGmail.putExtra(Intent.EXTRA_SUBJECT, subject);
if (body != null) sendIntentGmail.putExtra(Intent.EXTRA_TEXT, body);
mContext.startActivity(sendIntentGmail);
You can use below code:
Intent mailClient = new Intent(Intent.ACTION_VIEW);
mailClient.setClassName("com.google.android.gm",
"com.google.android.gm.ConversationListActivity");
startActivity(mailClient);

How to open Gmail application with value of email sent from my application and aumatically filled in gmail?

I am creating an application in which on viewing someone's profile i want to take the user to email after clicking a floating action bar
i can open gmail but i dont have email value filled already despite of sending its value
code:
fabtoemail.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmail = email;
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmail);
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Select Application"));
}
});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
Try like this
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","example#example.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "your subject here");
emailIntent.putExtra(Intent.EXTRA_TEXT, "if you want append some text");
startActivity(Intent.createChooser(emailIntent, "Send email..."));

Android: Email 'to ' field empty

I am developing an application for a hotel, where in, on booking a room, the app sends an email to the email-id given by the user. Now, i know it will use one of my default email clients, which is the gmail. The problem is, it is showing up with gmail's compose message window, with my message in the message body,but the 'to'field is empty. Any help?
here is the code:
public void sendmail(View vw)
{
name=et1.getText().toString();
to=et2.getText().toString();
phone=et3.getText().toString();
addr=et4.getText().toString();
Log.i("Send email", "");
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Thanks for using our app");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Hello mr"+name+"We just received an email with your details asking for a reservation:"+phone+" "+addr+"for room number"+x+"");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getBaseContext(), "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
}
From the documentation of EXTRA_EMAIL:
A String[] holding e-mail addresses that should be delivered to.
Something like this should work:
Intent mailIntent = new Intent(Intent.ACTION_SENDTO);
mailIntent.setData(Uri.parse("mailto:"));
mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
mailIntent.putExtra(Intent.EXTRA_SUBJECT, "Thanks for using our app");
mailIntent.putExtra(Intent.EXTRA_TEXT, "Hello mr"+name+"We just received an email with your details asking for a reservation:"+phone+" "+addr+"for room number"+x+"");
if (mailIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mailIntent);
} else {
// no e-mail app installed
}
Try this :
emailIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#to.com"});
email intent expects an String array but you're providing a string.So, it's not working in your case!

how to attach a String variable to an email

In Android Studio I wish to send an email on a button click. I am using the following code till I work out what is going on before I start changing thing.
String[] TO = {"ABC#yahoo.com.au"};
String[] CC = {"xyz#gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Some message added in here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
This works fine and well and shows up on my phone with the email content being as expected, however the email content, "Some message added in here" line is clearly hardcoded. I obviously wish to add in my own content by doing the following
String content = "Information I want to send";
emailIntent.putExtra(Intent.EXTRA_TEXT, content);
But for some reason the email content is blank. Why does is a string "content" recognised but a String variable x is not?
Check This Examples
By Looking at your code i only found problem in setting
emailIntent.setType(text/plain).
May Be you are using Gmail for sending mails(So you have to check second example).
Send Email (to Phone Email Client)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
Send Email (to Gmail)
Gmail does not examine the extra Intent fields, so in order to use this intent, you need to use the Intent.ACTION_SENDTO and pass a mailto: URI with the subject and body URL encoded.
String uriText =
"mailto:youremail#gmail.com" +
"?subject=" + Uri.encode("some subject text here") +
"&body=" + Uri.encode("some text here");
Uri uri = Uri.parse(uriText);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email"));

Intent Email in Android

i've got a mess about email intent in Android 4.1.1. here my code:
emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, "email#gmail.com");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "text");
But dialog just showed Bluetooth and Messages app. how can i show email app as in gmail in dialog? Can anyone help me, thanks so much!
Intent emailIntent;
emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:email#gmail.com"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "text");
if (emailIntent.resolveActivity(getPackageManager()) != null) {
startActivity(emailIntent);
} else {
//not_found_email_apps;
}
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {""};
String[] CC = {""};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
Above code should work for your query but it's look like you are testing it on Emulator, if you testing it on that than make sure any email client should be present for sending email, for ex. inbuilt Gmail client on mobile phone.
I've already found the reason that i met this wrong things. The reason was u have to set up applications included mail feature in its. I forgot set up one of them. So i've got this mess. thanks everyone helped me !

Categories

Resources