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.
Related
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);
}
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"));
I'm trying to make this program that when the user clicks a button, a message is sent to a whatsapp number
Here is the code in the onClick method
Uri uri = Uri.parse("smsto:" + "xxxxxxxxxx"); //xxx.. is the mobile number
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, "Check");
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
It shows that there are no apps that can perform this action. Why?
I removed
i.setType("text/plain");
And it works. But the text "Check" is not sent. How to do that if this is not the way.
Your format is slightly different from the example given on the WhatsApp FAQ, so I would modify to match.
From this page:
Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:
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(sendIntent);
However, if you prefer to share directly to WhatsApp and bypass the system picker, you can do so by using setPackage in your intent:
sendIntent.setPackage("com.whatsapp");
This would simply be set right before you call startActivity(sendIntent);
Try this code to send ON whatsapp
public void SendWhatsapp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
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);
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);