how to send a whatsapp message to a specific contact automatically?I have searched but it just opens the chat of that specific person but does not send the message automatically
Here is the code that am using:
private void openWhatsappContact(String number) {
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
I'm not sure you can send the message automatically, but try this to specify the message you want to send:
i.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
Reference:
https://www.whatsapp.com/faq/en/android/28000012
There is no direct way to do this because whatsapp does not offer an SDK interface.
You might have some luck with writing some accessibility automations or if you have root may be some xposed module.
Related
I've implemented a class that can send a mail. However, you can only write a topic and the message and when you click on "Send" you've to choose which app (Outlook or Gmail) you want to send the mail with and then write your e-mail. However, I want to make it possible for the user to send a mail directly from the my app instead of using another app. So I want to make it possible for the user to write his/her e-mail/gmail and message and then send the message to my e-mail. So in other words in the fragment I want an EditText where the user writes his/her e-mail/gmail, another EditText where the user writes the message and a button to send. How can this be implemented?
This is what I have done in my app to send a mail:
private void sendemail(String message) {
String [] reciever = new String[]{"myemail#hotmail.com"};
String subject = ("Feedback/Question");
Intent mailIntent = new Intent(Intent.ACTION_SEND);
mailIntent.putExtra(Intent.EXTRA_EMAIL, reciever);
mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
mailIntent.putExtra(Intent.EXTRA_TEXT, message);
mailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(mailIntent, "Choose an application to send your mail with"));
}
Use this library -> Send email in background. It will send an email from your app without users interaction.
Cheers!
using java mailApi,you must have to authenticate gmail app using credential.
please check this link:
Email via Java MailAPI
other link to provide custom class to send mail programatically.
https://stackoverflow.com/a/4345084/1223291
I hope its useful to you.
Use this method....
public void sendEmail()
{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"care#xyz.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "care Feedback");
intent.putExtra(Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(intent, "Send Email"));
}
I tried to search on Google but didn't find an appropriate answer.
I want to click a TextView and it will show a dialog that allows the user to choose optional email.
Any suggestion? Thanks in advance
Try this:
Intent intet = new Intent(Intent.ACTION_SEND);
intet.setType("message/rfc822");
intet.putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(intet);
This will open up a dialog that contains a list of apps installed on the device that can send an email.
Hope this helps. :)
A better option is to use the following, it will only open the applications that provide mail facility and not all apps that can share data.
Intent emailIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "subject" + "&body=" + "body" + "&to=" + email_id);
emailIntent.setData(data);
startActivity(emailIntent);
"subject" is the subject of mail, "body" is the content of the mail, and "email_id" is the id of the receiver of the mail.
You can keep the subject , body and email_id empty if you want the user to fill in the spaces.
for open gmail app
try this code:
Intent gmail = new Intent(Intent.ACTION_VIEW);
gmail.setClassName("com.google.android.gm","com.google.android.gm.ConversationListActivity");
startActivity(gmail);
I'm develop an app use mms message of android.
Currently I can:
Send ssm message but not attached image by use following code:
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("sms_body", message);
smsIntent.setData(Uri.parse("sms:" + phoneNumber));
((Activity) context).startActivityForResult(smsIntent, 0);
Send attach image via third party app:
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "Please see the attached image");
mmsIntent.putExtra(Intent.EXTRA_STREAM, attached_Uri);
LogUtils.debug(TAG, "extension: " + extension);
mmsIntent.setType(extension);
((Activity) context).startActivityForResult(mmsIntent, 0);
My problems:
Can't attach image to default messaging app of android.
How can i detect if default messaging app of android device ( such as tablet ) not exist.
So, please guild me on this problem.
Thanks you so much.
Solution for 1st problem
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "Please see the attached image");
mmsIntent.putExtra(Intent.EXTRA_STREAM, attached_Uri);
mmsIntent.setType("image/gif");
startActivity(Intent.createChooser(mmsIntent,"Send"));
Solution for 2nd problem
You don't have to worry about that, Playstore will.
If you are using sms feature you would have given permission. So your app will not be vissible in playstore for SMS featureless devices
EDIT:
To include the sender address add an additional EXTRA to the intent
mmsIntent.putExtra("address","number_here");
I am writing an application that needs to pre-populate an SMS message with the first name of the contact when using the stock android SMS messenger.
For example if my contacts name is Alex Smith.
When I select Alex Smith to type a message to, I want the text box to already have
'Alex, '
at the beginning of the SMS.
Please how can I achieve that?
Fetch the contact name from contacts, and do like as follows:
String contactName = "Alex"; // get it from selected contact
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", contactName+"," );
startActivity( intent );
Just look over here:
Send SMS via intent
You use a Intent to send the SMS and attach some pre defined text via the EXTRA_TEXT attribute. Quite easy to do. And it works for the normal SHARE intent as well.
You can't change system apps, but you can send "share intent" from your app to SMS App. As you remember, when you push "share" button in some apps, you can share smth with SMS. (You'll have SMS with text that app put in intent). SO, put contact's name in "share intent" and send it to SMS app.
it's bit late, but i hope it will help future users.
void prePopulateSMS(final String mblNumVar, final String smsMsgVar) {
Log.d(TAG, "prePopulateSMS called. smsMsgVar: " + smsMsgVar);
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", mblNumVar);
smsIntent.putExtra("sms_body", smsMsgVar);
startActivity(smsIntent);
}
I am trying to send msg body and contacts from my app to other available sms apps like whatsapp, default sms app, skype etc. But it is working properly for only default app and for others it is either taking only msg body or only contacts...I have tried other Actions like SEND also..
Uri uri = Uri.parse("smsto:" + destination);
Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra(Intent.EXTRA_TEXT, editMessage.getText().toString());
startActivity(Intent.createChooser(intent, "Share with"));
Try this code:
data.setAction(Intent.ACTION_VIEW);
data.setData(Uri.parse("sms:(234) 567-8901"));
data.putExtra(Intent.EXTRA_TEXT, "Hello from "+getResources().getString(R.string.app_name));
It works for me.