mailto Intent doesn't show recipient address (Android studio) - java

Im trying to send an email from my Android app. With the click of a button, gmail should open and show a new email with my previously defined recipient, subject and email body.
This was how it was working for 2 days but today, the recipient address is not getting copied to the gmail address bar -- only subject and body are getting copied.
this is my code (i havent changed it -- its the same as it was 2 days back):
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, recipient);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}

Add recipient address in String Array,:
Try this code:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{recipient});
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}

Related

Email ID , Subject and Message not setting in android Send Intent

I am sending email using intent but the subject and message body is not being set.
Intent sendMail = new Intent(Intent.ACTION_SEND);
sendMail.setType("*/*");
sendMail.setType("message/html");
sendMail.setPackage("com.google.android.gm");
sendMail.putExtra(Intent.EXTRA_EMAIL , email);
sendMail.putExtra(Intent.EXTRA_SUBJECT , subject);
sendMail.putExtra(Intent.EXTRA_TEXT , message);
startActivity(Intent.createChooser(sendMail , "Choose an Email Client"));
I also faced this problem. Be clear that those string values are not null. You could also use ACTION.SENDTO. Use the below code; it worked for me.
Intent sendMail = new Intent(Intent.ACTION_SENDTO);
sendMail.setData(Uri.parse("mailto:"));
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setSelector( sendMail );
startActivity(Intent.createChooser(intent, "Choose an Email Client"));

Debugging an Android intent problem (no specific receivers)

I have a problem that I want in my application to have a specific email receiver whenever the user press the email button it shows to him/her a fixed receiver. How can I do this?
public void google(View v){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
Intent shareIntent = Intent.createChooser(emailIntent,"");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shareIntent);
}
this is the code
this is the image of email
Use this code hope it will help
Intent Email = new Intent(Intent.ACTION_SEND);
String[] recipents ={"your_recepient_email"};
Email.putExtra(Intent.EXTRA_EMAIL,recipents);
Email.setType("text/html")
Email.setPackage("com.google.android.gm");
startActivity(Intent.createChooser(Email, "Send mail"));
If you want subject and content use the code like how you added the lines for subject.

no app to perform this action android email

There are plenty of people with this issue but none of their solution apply on mine, I try to change the Type from rfc822 to plaintext, open the email in my emulator and set an account, use intent action_sendto Uri.parse"mailto:", action send.
Do I need to install something in the emulator or this really work for a real phone?
send =(Button) findViewById(R.id.send_button);
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"myemail#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "HEY");
emailIntent.putExtra(Intent.EXTRA_CC, "example#gmail.com");
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Choose an Email client :"));
} catch (ActivityNotFoundException anfe) {
Toast toast = Toast.makeText(email.this, "Sorry, no email client found", Toast.LENGTH_LONG);
toast.show();
}
}
}
);
Below code is working,
Use this code to send E-mail
publicvoid sendEmail() {
Log.i("Send email", "");
String[] TO = {""}; // Array of email address whom you want to send email
String[] CC = {""}; // Array of email address whom you want to keep in CC
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); // E-mail Addresss
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject"); // Email Subject
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here"); // your E-mail body
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();
}
}
For more info
Intent Object - Action to send Email You will use ACTION_SEND action to launch an email client installed on your Android device. Following is simple syntax to create an intent with ACTION_SEND action
Intent emailIntent = new Intent(Intent.ACTION_SEND);
Intent Object - Data/Type to send Email To send an email you need to specify mailto: as URI using setData() method and data type will be to text/plain using setType() method as follows −
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
Intent Object - Extra to send Email
EXTRA_BCC
A String[] holding e-mail addresses that should be blind carbon copied.
EXTRA_CC
A String[] holding e-mail addresses that should be carbon copied.
EXTRA_EMAIL
A String[] holding e-mail addresses that should be delivered to.
EXTRA_HTML_TEXT
A constant String that is associated with the Intent, used with ACTION_SEND to supply an alternative to EXTRA_TEXT as HTML formatted text.
EXTRA_SUBJECT
A constant string holding the desired subject line of a message.
EXTRA_TEXT
A constant CharSequence that is associated with the Intent, used with ACTION_SEND to supply the literal data to be sent.
EXTRA_TITLE
A CharSequence dialog title to provide to the user when used with a ACTION_CHOOSER.

Android - getting an error “no application can perform this action” while trying to send a whatsapp message?

I am practising by making an app in which the user can send a WhatsApp message to a particular person .I tried some code snippets which i found on internet but whenever i try to send a WhatsApp msg from an actual device, i am gettig an error "No Application can perform this action".
Here is my code:-
public void sendMessage(View v) {
try
{
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
}catch (Exception e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
}
Please help .
You receive no application can perform this action because you should remove i.setType("text/plain"); from your code:
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
Unfortunately as you can see WhatsApp now opens in the conversation activity but there isn't the text you set in the Intent. This is because WhatsApp doesn't support this kind of share. The only supported share with Intent is ACTION_SEND as you can see in the WhatsApp FAQ:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);

How to call default email application from my android application

I am new to Android application development and with very little java knowledge. I want to call the default Android email application from my application once a button is clicked. What code should i use ?
Thanks And Regards.
You can create an email intent for that:
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"address#domain.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Some Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Some body");
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
In Android, you launch other activities by sending an intent to the android OS. The OS will then determine what activities subscribe to the intent, and either use a default or allow the user to select one. Use the following intent to just launch email:
Intent email = new Intent(android.content.Intent.ACTION_SEND)
You can also include a default subject, to field, content, etc by using the bundle on the intent. There is a great tutorial here
try this code
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("plain/text");
sendIntent.setData(Uri.parse("demoemail#gmail.com"));
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demoemail#gmail.com" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "demo of email");
sendIntent.putExtra(Intent.EXTRA_TEXT, "hi my message");
startActivity(sendIntent);

Categories