Describe sending SMS messages programmatically?

Submitted by: Administrator
Take a button on activity_main.xml file as follows.

<Button android:id="@+id/btnSendSMS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:onClick="sendmySMS" android:text="sendSMS" />

According to above code when user clicks the button sendmySMS method will be called. sendmySMS is user defined method.

In the AndroidManifest.xml file, add the following statements

<uses-permissionandroid:name="android.permission.SEND_SMS"/>

Now we write the final step. Write the given below method in MainActivity,java file

publicvoidsendmySMS(View v)
{
SmsManagersms = SmsManager.getDefault();
sms.sendTextMessage("5556", null, "Hello from google", null, null);
}
In this example I have used two emulator. On the first Android emulator (5554), click the Send SMSbutton to send an SMS message to the second emulator(5556).
Submitted by:

Read Online Android Job Interview Questions And Answers