Reputation: 575
I am working on android social networking app. In that I need to send invitation to the contacts in my phone. i.e when i click on invite button it should open contacts from phone and when a specific contact is selected it should open the send message activity to send default sms. How can I do that? I was able to open the contacts when invite button is clicked. But how to send sms from my app to a selected contact. Any help in this regard will be really thankful.
Upvotes: 0
Views: 1648
Reputation: 550
Use this code on your activity to send sms
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phonenumber, null, message, null, null);
Set below permission in manifest
<uses-permission android:name="android.permission.SEND_SMS" />
Upvotes: 2
Reputation: 1390
You can use SmsManager
class.
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
or built-in android sms application.
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Note: both need SEND_SMS
permission
<uses-permission android:name="android.permission.SEND_SMS" />
Upvotes: 2