I have an EditText, and a Button. The ET is for adding an email address, and the button is for sending the email. I'm trying to accomplish this without any more steps (aka don't want a chooser). Can someone point me in the right direction please, it seems like such a simple thing to do, but every time I try to do this without a chooser, I get an exception.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"user#email.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "some text");
try {
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(FinalAction.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Related
String url ="https://m.facebook.com/messages/read/?fbid=101631428274763";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
I want to directly send some messages. This way I am able to send message to fb page...but, not able to add some texts to text field. So, how can I send messages? I know that I can do that by intent.putExtra but, what the name would be?
Here is You sent a message direct to FB messenger.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "My message to send");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");
try {
startActivity(sendIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.show(this, "Please Install Facebook Messenger");
}
Following source code worked properly for me
Uri uri = Uri.parse("fb-messenger://user/101631428274763");
Intent toMessenger= new Intent(Intent.ACTION_VIEW, uri);
toMessenger.putExtra(Intent.EXTRA_TEXT, "My message to send");
try {
startActivity(toMessenger);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
}
I don't want to send emails to other users. I only want to open the launching activity of Email. I have tried it through different ways but every time send email(compose) is opening. But i want to open Email app only nothing else(Sent, outbox, spam, Trash etc).
My code is below
Intent intent = new Intent(Intent.ACTION_SENDTO)
.setData(Uri.parse("mailto:"));
//check if the target app is available or not
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Again, This code opens the send email to(compose) option. But i want to open Email app only nothing else(Sent, outbox, spam, Trash etc).
Use this code to open default Mail Application :
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_EMAIL);
this.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(Dashboard.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
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();
}
}
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.
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);