Send SMS using SmsManager
Send SMS using SmsManager API in Android Studio
Project Details: Send SMS using SmsManager
Sending SMS messages can be very useful to communicate with other people. Developers can also leverage SMS messaging in their apps by using the smsmanager API. The API allows apps to send SMS text messages, schedule SMS messages, and monitor the number of outgoing and incoming SMS messages.
Android apps can send and receive SMS text messages from the cloud or other Android devices. Developers can also use the smsmanager API to interact with their apps from a mobile phone or a computer’s operating system.
This illustration is utilizing the smsManager API to convey the SMS message.
Send SMS using SmsManager: Step 1 - Android Layout
Path: res >> layout > main.xml
Send SMS using SmsManager: Step 2 - SendSMSActivity.java
SendSMSActivity.java Activity to send SMS via smsManager.
public class SendSMSActivity extends Activity {
Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonSend = (Button) findViewById(R.id.buttonSend);
textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
textSMS = (EditText) findViewById(R.id.editTextSMS);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
Step 3 Add Permission into Manifest file.
I hope the above article is of help to you for your learning and future project.