Interview answers verified by specialists.

Find interview questions and answers on this website:


See right interview answers on 30 common job interview questions

How to send SMS in android? Explain with example?

SMS messaging is one of the basic and important applications on a mobile phone. Now days every mobile phone has SMS messaging capabilities, and nearly all users of any age know how to send and receive suchmessages. Mobile phones come with a built-in SMS application that enables you to send and receiveSMS messages. If you want to send the SMS programmatically then follow the following steps.

Sending SMS Messages Programmatically

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 careerRide", 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).

Do you know that?

When trying to get creative juices flowing, an ambient level of music appears to work best Next

Articles:

Popular:

Fast Payments
Payoneer sing up to get free 
$25