Tuesday, June 30, 2015

Send SMS in android

You can use this to send sms to any number.
Use this in XML
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:onClick="sendsms"
        android:id="@+id/button2"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
Use this in Activity Class
 public void sendsms(View view) {
        String phoneNumber = "+880xxxxxxxxxx";
        String message = "Welcome to sms";
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
        intent.putExtra("sms_body", message);
        startActivity(intent);
    }
Need SEND_SMS permission.
<uses-permission android:name="android.permission.SEND_SMS" />

No comments:

Post a Comment