For each product from my website there is a link SMS to send sms, PHONENUMBER is different from one product to another.how can I go through the link and save everything that appears after " sms: " ?
I want to save the phone number in a variable and set this with intend to be filled in sendto adress field,how can i do that?
ponumber=???; // this can not be predefine
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", ponumber);
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);
Related
I am using this code to call WhatsApp directly from my Call Logs app. This works well, but only if the phone number includes a valid country code. For example calling WhatsApp with 919789006685 works but calling it with 97890 06685 does not work. Here 91 is the country code.
Since my app reads phone numbers from Call Logs, I should be able to invoke WhatsApp with any valid contact phone number, irrespective of the stored phone number format. It is possible that users store numbers in their contacts which do not include country codes. So is there a workaround for this issue?
Code used within my app:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
String waNumber = contactPhone.replace("+", "");
sendIntent.putExtra("jid", waNumber + "#s.whatsapp.net");
startActivity(sendIntent);
Here is the complete solution. May be useful for people who are trying the same from their apps. Thanks to Sourav Ganguly for the link.
android-make whatsapp call
Retreive the ID for the selected Contact.
Get all the RAW Contact Id's for the contact id from ContactsContract.RawContacts
Query the ContactsContract.Data table for all Raw Contacts and retrieve the column ContactsContract.Data._ID
Since a contact may have several phone numbers active on WhatsApp, you may want to check additionally the column ContactsContract.Data.DATA3 to filter out the phone number you want to match
To start a WhatsApp conversation use vnd.android.cursor.item/vnd.com.whatsapp.profile and vnd.android.cursor.item/vnd.com.whatsapp.voip.call if you want to start a WhatsApp call
Use the ID from step 3 to start WhatsApp. Here is sample code:
String data = "content://com.android.contacts/data/" + dataId;
String type = "vnd.android.cursor.item/vnd.com.whatsapp.profile";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.setDataAndType(Uri.parse(data), type);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
WhatsApp for an specific phone number
val whatsAppIntent = Intent(Intent.ACTION_VIEW)
val encodedText = URLEncoder.encode("Helo World", "UTF-8")
whatsAppIntent.data = Uri.parse("http://api.whatsapp.com/send?phone=$phoneNumber&text=$encodedText")
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<p>https://play.google.com/store/apps/details?id=" + context.getPackageName() + "</p>"));
context.startActivity(Intent.createChooser(sharingIntent, "Share using"));
i already know the code how to send sms by typing the number and the message, but what i want to know is it possible to send message only without typing the contact number? Here’s my situation, im working at water district, I’m making app for reporting leak thru text, what i want to happen is, the reporter is only need to type the message then send, without inputting the number. We only have 1 hotline number, so I don’t think the reporter need to type the contact number everytime the reporter text us, he just need to type the message then click send only.
send sms without inputting contact number
Following code works without inputting the number again and again. The address attribute stores the number(hotline number) and When user clicks on report it default takes you to messaging app with number already stored and allow to write the text and go.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms/");
intent.putExtra("address", your_hotline_number);
intent.putExtra("sms_body", " ");
startActivity(intent);
Try this it's working for me:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", "12345", null)));
Keep the recipient number in a constant field as
public static final String recipientNo = "*********";
Then if you use implicit intent the add below code
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + recipientNo));
intent.putExtra("sms_body", message);
startActivity(intent);
or if you use SmsManager,
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
and add permission in AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
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 want to choice a app to send email:only email app to send my email,i have read How to open Email program via Intents (but only an Email program) i used intent.setType("message/rfc822") ,it very well,but Bluetooth and email give me to choice,i want to remove Bluetooth,and want to Leave only email.can you tell me how to send email not to show Bluetooth to give mo choice;
edit: if i used Intent intent = new Intent(Intent.ACTION_SENDTO); the bluetooth is remove but add Text messages t0 give me choice.i also used
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
the bluetooth also remove but also add add Text messages t0 give me choice.is there i way to only email app to send email?