title: How to make a phone number clickable to use in sms service in android?
body: <p>I have a phone number in my xml layout and I want to make it clickable such that it would automatically get entered in sms service and I can send sms to the number.</p>
  
  <p><a href="https://i.stack.imgur.com/6liay.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6liay.png" alt="enter image description here"></a></p>
  
  <p><strong>Alinas.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginRight="10dp"
      android:layout_marginTop="5dp"
      android:layout_marginLeft="10dp"
      android:background="#ffffff"&gt;
  
      &lt;ImageView
          android:layout_width="160dp"
          android:layout_height="140dp"
          android:layout_marginLeft="10dp"
          android:layout_marginTop="10dp"
          android:background="@drawable/alina_sbakerycafe"
          android:id="@+id/imageView" /&gt;
  
      &lt;TextView
          android:layout_width="2500dp"
          android:layout_height="50dp"
          android:text="Alina's Bakery Cafe"
          android:textStyle="bold"
          android:textSize="25dp"
          android:gravity="end"
          android:textAlignment="textEnd"
          android:layout_alignTop="@+id/imageView"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="42dp" /&gt;
  
      &lt;TextView
          android:layout_width="300dp"
          android:layout_height="50dp"
          android:text="Address:   New Baneswor, Kathmandu  Phone No.:\t 9841123456"
  
          android:textAlignment="center"
          android:textSize="15dp"
          android:layout_centerVertical="true"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;Button
          android:layout_width="@android:dimen/thumbnail_width"
          android:layout_height="@android:dimen/app_icon_size"
          android:onClick="moveToActivityViewMenu"
          android:background="@drawable/button"
          android:text="View Menu"
          android:textColor="#ffffff"
          android:layout_marginBottom="83dp"
          android:id="@+id/button"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>After I click in the phone number it should automatically get entered here:</p>
  
  <p><a href="https://i.stack.imgur.com/TYnX0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TYnX0.png" alt="enter image description here"></a></p>
  
  <p><strong>SendSMSActivity.java</strong></p>
  
  <pre><code>package com.golo.acer.mrestro4;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.telephony.SmsManager;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  
  public class SendSmsActivity extends Activity {
  
      Button sendSmsBtn;
      EditText toPhoneNumber;
      EditText smsMessageET;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_send_sms);
  
          sendSmsBtn = (Button) findViewById(R.id.btnSendSMS);
          toPhoneNumber = (EditText) findViewById(R.id.editTextPhoneNo);
          smsMessageET = (EditText) findViewById(R.id.editTextSMS);
  
          sendSmsBtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  sendSms();
              }
          });
      }
  
      private void sendSms() {
          String toPhone = toPhoneNumber.getText().toString();
          String smsMessage = smsMessageET.getText().toString();
  
          try {
              SmsManager smsManager = SmsManager.getDefault();
              smsManager.sendTextMessage(toPhone, null, smsMessage, null, null);
  
              Toast.makeText(this, "SMS sent", Toast.LENGTH_LONG).show();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
      public void goToInbox(View v) {
          Intent intent = new Intent(SendSmsActivity.this, ReceiveSMSActivity.class);
          startActivity(intent);
      }
  
      public void moveToSmsActivity(View view) {
          Intent intent = new Intent(this, SmsActivity.class);
          startActivity(intent);
      }
  }
  </code></pre>