I am working on an android application , in which we are dealing with android sms service. I just want to know that is it possible to send sms to other non android device using the below method.
SmsManager sm = SmsManager.getDefault();
// HERE IS WHERE THE DESTINATION OF THE TEXT SHOULD GO
String number = "6508570720";
sm.sendTextMessage(number, null, "Test SMS Message", null, null);
OR
Do we have any other method to achieve this task.
SMS is not a device specific feature. It is provided and controlled by Telecom / Cellular service provider. So the code should send SMS to any phone from your Android device.
You may also try the following code:
String number = "6508570720";
String message = "hi there";
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + number ) ); intent.putExtra( "sms_body", message ); startActivity( intent );
Yep, This should work for sending sms to non-android devices as well.
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"/>
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.
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 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 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?