When I use the following code:
String phoneNumber="0527276513";
Uri uri = Uri.parse("smsto:" + phoneNumber.toString());
Intent smsSIntent = new Intent(Intent.ACTION_SENDTO, uri);
String smsBody="hii";
smsSIntent.putExtra("sms_body", smsBody.toString());
startActivity(smsSIntent);
The code opens the default application for sending SMS in my phone with the SMS body but the message doesn't get sent.
How do I send an SMS dynamically?
It is simple. Before making any changes please update your manifest by adding the following line:
<uses-permission android:name="android.permission.SEND_SMS"/>
And in your method/function use the following code:
String phoneNumber = "myphonenumber";
String message = "mymessage";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
Note that on Android 4.4 (KitKat) and higher devices, only the default SMS app can send text messages, per the blog post.
Assuming your app is not a full fledged SMS replacement app, the approach you have outlined is the correct one to ensure your app works on all Android versions.
Related
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"/>
How do I add an "attachment" into my SmsManager object when I'm trying tro send an sms?
My current function for sending a normal sms is:
public void send() {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(this.number, null, this.message, null, null);
}
I have looked a little bit at the sendDataMessage() but don't really understand it.. any help is appreciated.
Thanks.
EDIT
I don't want to use Intent for this. I have a List with Bitmap images that I want to send via an SMS/MMS. So I don't want to invoke the SMS app in my application. I want to send attachments "dynamically" depending on what's in my List.
SOLUTION
A friend of mine just posted me this link to a library: https://github.com/klinker41/android-smsmms
Message mMessage = new Message(textToSend, addressToSendTo);
mMessage.setImage(mBitmap); // not necessary for voice or sms messages
mMessage.setType(Message.TYPE_SMSMMS); // could also be Message.TYPE_VOICE
Haven't tried it yet, but it seems to be the real deal. Hope it's for good use for someone else too.
follow the code
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
and add permission
<uses-permission android:name="android.permission.SEND_SMS" />
I'm trying to send a text message from my Android application. Everything works fine, but some of the text are missing. Here is my code:
String phoneNumber = "99********"; //Masked the number intentionally.
String message = "";
message += "This is Prabha, and thanks for using my application. ";
message += "Hope you enjoy this application. ";
message += "If you face any problem or issue, you can report the issue to our ";
message += "official mail id: pbha701#yahoo.com.";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
I am receiving the message, but it is not full. Some text are missing. I'm getting only the below text:
This is Prabha, and thanks for using my application. Hope you enjoy this application. If you face any problem or issue, you can report the issue to our officia
I've added the below permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.SEND_SMS" />
I am not able to find why the remaining text are truncated. Should I add any other permission or any setting changes required? Any ideas or help will be appreciated.
Thanks.
You need to use sendMultipartTextMessage() method available in SmsManager class.
sendTextMessage() method available in SmsManager class can send a text message of length 160 characters only.
To send multi-part SMS, divide the message using divideMessage() method available in SmsManager class. Then send this parts as an parameter in sendMultipartTextMessage(), as shown below:
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> parts = smsManager.divideMessage(message);
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);
I want read information of sms outgoing that sended by class SmsManager in Android not by default application messenger in device. Any idea for help me? Many thank all of you!
Nothing is saved by SmsManager. The messages are sent to their recipient over the mobile network, and that is it.
Individual apps may save messages that they also send via SmsManager. The details of which apps save what would depend upon the apps.
Please follow the following two steps:
1. Send your message
2. Insert the message to "sent" messages box
SmsManager smsManager = SmsManager.getDefault();
String address = "address here";
String text = "text message here";
// Send you message
smsManager.sendTextMessage(address, null, text, null, null);
Uri uri = Uri.parse("content://sms/sent/");
ContentValues values = new ContentValues();
values.put("address", address);
values.put("body", text);
// Insert the message to "sent" messages box
getContentResolver().insert(uri, values);
PS: You can check the complete code here
I want to use the existing sms application in android phones and add some features.
How to use them.i want the entire functionality including interface, logging as thread etc.
Thanks in advance
Not sure what you want to do here:
Simple way:
SmsManager mgr = SmsManager.getDefault();
String phoneNumber = "12345667860";
mgr.sendTextMessage(phoneNumber, null, "Sup bbz", null, null);
Alternate way using intents:
String phoneNumber = "12345667860";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", phoneNumber, null)));
Android uses intents to communicate between processes in the dvm.
Read the documentation to know more about the exposed api