I am sending mail through my application mail is sent but the attached text is not sent with it.
public class Email extends Activity {
Button send;
EditText address, subject, emailtext;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share);
send=(Button) findViewById(R.id.btnsubmitShare);
address=(EditText) findViewById(R.id.edittexttoShare);
subject=(EditText) findViewById(R.id.edittextsubjectShare);
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/octet-stream");
// final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
Email.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
}
}
From this application user can share a link, although mail is sent from it but text is empty
The problem is you are doing
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
when you should make a call to toString(), so it's going to be:
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText().toString());
Related
I would like to know how to open the Activity for composing email in gmail or outlook. By now I only know ho to be redirected to for instance gmail but I would also open the "composer" (or whatever) and add an email address. I've already tried with:
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
but doesnot work
full source to the test-app
public class MainActivity extends AppCompatActivity {
private static final String GOOGLE_MAIL = "com.google.android.gm";
private static final String OUTLOOK = "com.microsoft.office.outlook";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test(GOOGLE_MAIL);
}
private void test(String mail) {
Intent intent = getPackageManager().getLaunchIntentForPackage(mail);
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
startActivity(intent);
}
}
You can try this:
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {"someone#gmail.com"};
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, "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();
}
}
I dynamically created buttons and I want to send an email by clicking on these buttons, but something goes wrong. Nothing happens. :( Please help me, I am beginner.
AdapterListingOrders:
public class AdapterListingOrders extends AppCompatActivity {
private Button btnAccRejOrders;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adapter_listing_orders);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
btnAccRejOrders = (Button) findViewById(R.id.order_acc_rej);
btnAccRejOrders.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
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");
}
});
}
}
But onClick does not work. When I press the btnAccRejOrders, LogCat display:
ViewPostImeInputStage processPointer 0
ViewPostImeInputStage processPointer 1
btnAccRejOrders.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("Send email", "");
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();
}
}
});
hello i am trying to send an email from an android application , the below code is working fine since it is opening the email app configured on the phone but the problem is it is not taking the subject and the Bcc any ideas
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
As you can see in the getting the address you got the text by .getText(); then you made it a string for other uses, because it was an editable text from editText. But in the other EditTextss you forgot to add .toString(); so you can use it as a string in email.
try this:
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
please ask if you didn't understand
Try
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
EditText.getText() return a editable you need to change it to String by applying toString();
Will work 100%
String[] to = value.toString().split(",");
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, to);
i.putExtra(Intent.EXTRA_BCC, "array of bcc like to");
i.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.share_email_subject), IN_SHARE_CAPTION));
i.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(IjoomerUtilities.prepareEmailBody(message == null ? "" : message, getSmartApplication().readSharedPreferences().getString(SP_USERNAME, "") + " " + getString(R.string.saw_this_story_on_the) + " "
+ getString(R.string.app_name) + " " + getString(R.string.thought_you_should_see_it), IN_SHARE_CAPTION, IN_SHARE_DESCRIPTION, IN_SHARE_SHARELINK, getString(R.string.try_ijoomeradvance), getString(R.string.site_url))));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
ting(getString(R.string.share_email_no_client));
}
Hi friends,
I need to send zip file as attachment to email. I have tried using code below. However, I receive email message without the attachment. What am I doing wrong?
public class MainActivity extends Activity {
Button email;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email=(Button)findViewById(R.id.button1);
email.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"radha#impressol.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Email Message");
intent.setType("application/zip");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://+/sdcard/zipname.zip"));
startActivity(Intent.createChooser(intent, "Send Email"));
}
});
}
}
In your case remove the "+" from Uri string.
P.S. it'll also work without Uri protocol, like (Environment.getExternalStorageDirectory()+"/zipname.zip");
public class AndroidEmailActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText edittextEmailAddress = (EditText) findViewById(R.id.email_address);
final EditText edittextEmailSubject = (EditText) findViewById(R.id.email_subject);
final EditText edittextEmailText = (EditText) findViewById(R.id.email_text);
Button buttonSendEmail_intent = (Button) findViewById(R.id.sendemail_intent);
buttonSendEmail_intent.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String emailAddress = edittextEmailAddress.getText().toString();
String emailSubject = edittextEmailSubject.getText().toString();
String emailText = edittextEmailText.getText().toString();
String emailAddressList[] = { emailAddress };
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailText);
startActivity(Intent.createChooser(intent,
"Choice App t send email:"));
}
});
}
}
This is my code.I am not getting any emails.I need to send emails through this intent method.how can I acheive that?Where I went wrong?pls give some suggestions.
I am getting the error when I click the Send email button as "No applications can perform this action."
This is my code to send emails:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.share_email_subject));
sendIntent.setType("message/rfc822");
activity.startActivity(Intent.createChooser(sendIntent, "Choose Email Client"));
Try removing the plain/text type?
It is Good practice to work with original device rather than on Virtual Device. I suggest you try this code block on real device.
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("plain/text");
startActivity(Intent.createChooser(sendEmail, "Email:"));
If you want to see more on Email with Intent then refer to this post:
http://androidtutforbeginner.blogspot.com/2012/03/send-email-with-intent-in-android.html