<p >In Android, you can use SmsManager API or devices Built-in SMS application to send SMS&#39;s. In this tutorial, we shows you two basic examples to send SMS message &minus;</p> <p ><b >SmsManager API</b></p> <pre class="prettyprint notranslate prettyprinted" > <span class="typ" >SmsManager</span><span class="pln" > smsManager </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >SmsManager</span><span class="pun" >.</span><span class="pln" >getDefault</span><span class="pun" >();</span><span class="pln" > smsManager</span><span class="pun" >.</span><span class="pln" >sendTextMessage</span><span class="pun" >(</span><span class="str" >&quot;phoneNo&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >null</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;sms message&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >null</span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >null</span><span class="pun" >);</span></pre> <p ><b >Built-in SMS application</b></p> <pre class="prettyprint notranslate prettyprinted" > <span class="typ" >Intent</span><span class="pln" > sendIntent </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pun" >(</span><span class="typ" >Intent</span><span class="pun" >.</span><span class="pln" >ACTION_VIEW</span><span class="pun" >);</span><span class="pln" > sendIntent</span><span class="pun" >.</span><span class="pln" >putExtra</span><span class="pun" >(</span><span class="str" >&quot;sms_body&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;default content&quot;</span><span class="pun" >);</span><span class="pln" > sendIntent</span><span class="pun" >.</span><span class="pln" >setType</span><span class="pun" >(</span><span class="str" >&quot;vnd.android-dir/mms-sms&quot;</span><span class="pun" >);</span><span class="pln" > startActivity</span><span class="pun" >(</span><span class="pln" >sendIntent</span><span class="pun" >);</span></pre> <p >Of course, both need<b >SEND_SMS permission</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;uses-permission</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.permission.SEND_SMS&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span></pre> <p >Apart from the above method, there are few other important functions available in SmsManager class. These methods are listed below &minus;</p> <table class="table table-bordered" > <tbody > <tr > <th >Sr.No.</th> <th >Method &amp; Description</th> </tr> <tr > <td >1</td> <td ><b >ArrayList&lt;String&gt; divideMessage(String text)</b> <p >This method divides a message text into several fragments, none bigger than the maximum SMS message size.</p> </td> </tr> <tr > <td >2</td> <td ><b >static SmsManager getDefault()</b> <p >This method is used to get the default instance of the SmsManager</p> </td> </tr> <tr > <td >3</td> <td ><b >void sendDataMessage(String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent)</b> <p >This method is used to send a data based SMS to a specific application port.</p> </td> </tr> <tr > <td >4</td> <td ><b >void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList&lt;String&gt; parts, ArrayList&lt;PendingIntent&gt; sentIntents, ArrayList&lt;PendingIntent&gt; deliveryIntents)</b> <p >Send a multi-part text based SMS.</p> </td> </tr> <tr > <td >5</td> <td ><b >void sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)</b> <p >Send a text based SMS.</p> </td> </tr> </tbody> </table> <h2 >Example</h2> <p >Following example shows you in practical how to use SmsManager object to send an SMS to the given mobile number.</p> <blockquote >To experiment with this example, you will need actual Mobile device equipped with latest Android OS, otherwise you will have to struggle with emulator which may not work.</blockquote> <table class="table table-bordered" > <tbody > <tr > <th class="fivepct" >Step</th> <th >Description</th> </tr> <tr > <td >1</td> <td >You will use Android Studio IDE to create an Android application and name it as<i >tutorialspoint</i>under a package<i >com.example.tutorialspoint</i>. While creating this project, make sure you<i >Target SDK</i>and<i >Compile With</i>at the latest version of Android SDK to use higher levels of APIs.</td> </tr> <tr > <td >2</td> <td >Modify<i >src/MainActivity.java</i>file and add required code to take care of sending email.</td> </tr> <tr > <td >3</td> <td >Modify layout XML file<i >res/layout/activity_main.xml</i>add any GUI component if required. I&#39;m adding a simple GUI to take mobile number and SMS text to be sent and a simple button to send SMS.</td> </tr> <tr > <td >4</td> <td >No need to define default string constants at res/values/strings.xml. Android studio takes care of default constants.</td> </tr> <tr > <td >5</td> <td >Modify<i >AndroidManifest.xml</i>as shown below</td> </tr> <tr > <td >6</td> <td >Run the application to launch Android emulator and verify the result of the changes done in the application.</td> </tr> </tbody> </table> <p >Following is the content of the modified main activity file<b >src/com.example.tutorialspoint/MainActivity.java</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >package</span><span class="pln" > com</span><span class="pun" >.</span><span class="pln" >example</span><span class="pun" >.</span><span class="pln" >tutorialspoint</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >os</span><span class="pun" >.</span><span class="typ" >Bundle</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >Activity</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >telephony</span><span class="pun" >.</span><span class="typ" >SmsManager</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >util</span><span class="pun" >.</span><span class="typ" >Log</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >Menu</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >View</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Button</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >EditText</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Toast</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >class</span><span class="pln" > </span><span class="typ" >MainActivity</span><span class="pln" > </span><span class="kwd" >extends</span><span class="pln" > </span><span class="typ" >Activity</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Button</span><span class="pln" > sendBtn</span><span class="pun" >;</span><span class="pln" > </span><span class="typ" >EditText</span><span class="pln" > txtphoneNo</span><span class="pun" >;</span><span class="pln" > </span><span class="typ" >EditText</span><span class="pln" > txtMessage</span><span class="pun" >;</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onCreate</span><span class="pun" >(</span><span class="typ" >Bundle</span><span class="pln" > savedInstanceState</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onCreate</span><span class="pun" >(</span><span class="pln" >savedInstanceState</span><span class="pun" >);</span><span class="pln" > setContentView</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >activity_main</span><span class="pun" >);</span><span class="pln" > sendBtn </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >btnSendSMS</span><span class="pun" >);</span><span class="pln" > txtphoneNo </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >EditText</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >editText</span><span class="pun" >);</span><span class="pln" > txtMessage </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >EditText</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >editText2</span><span class="pun" >);</span><span class="pln" > sendBtn</span><span class="pun" >.</span><span class="pln" >setOnClickListener</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >View</span><span class="pun" >.</span><span class="typ" >OnClickListener</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onClick</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > sendSMSMessage</span><span class="pun" >();</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >});</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > sendSMSMessage</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Log</span><span class="pun" >.</span><span class="pln" >i</span><span class="pun" >(</span><span class="str" >&quot;Send SMS&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >String</span><span class="pln" > phoneNo </span><span class="pun" >=</span><span class="pln" > txtphoneNo</span><span class="pun" >.</span><span class="pln" >getText</span><span class="pun" >().</span><span class="pln" >toString</span><span class="pun" >();</span><span class="pln" > </span><span class="typ" >String</span><span class="pln" > message </span><span class="pun" >=</span><span class="pln" > txtMessage</span><span class="pun" >.</span><span class="pln" >getText</span><span class="pun" >().</span><span class="pln" >toString</span><span class="pun" >();</span><span class="pln" > </span><span class="kwd" >try</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >SmsManager</span><span class="pln" > smsManager </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >SmsManager</span><span class="pun" >.</span><span class="pln" >getDefault</span><span class="pun" >();</span><span class="pln" > smsManager</span><span class="pun" >.</span><span class="pln" >sendTextMessage</span><span class="pun" >(</span><span class="pln" >phoneNo</span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >null</span><span class="pun" >,</span><span class="pln" > message</span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >null</span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >null</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >makeText</span><span class="pun" >(</span><span class="pln" >getApplicationContext</span><span class="pun" >(),</span><span class="pln" > </span><span class="str" >&quot;SMS sent.&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >LENGTH_LONG</span><span class="pun" >).</span><span class="pln" >show</span><span class="pun" >();</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >catch</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Exception</span><span class="pln" > e</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >makeText</span><span class="pun" >(</span><span class="pln" >getApplicationContext</span><span class="pun" >(),</span><span class="pln" > </span><span class="str" >&quot;SMS faild, please try again.&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >LENGTH_LONG</span><span class="pun" >).</span><span class="pln" >show</span><span class="pun" >();</span><span class="pln" > e</span><span class="pun" >.</span><span class="pln" >printStackTrace</span><span class="pun" >();</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >boolean</span><span class="pln" > onCreateOptionsMenu</span><span class="pun" >(</span><span class="typ" >Menu</span><span class="pln" > menu</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="com" >// Inflate the menu; this adds items to the action bar if it is present.</span><span class="pln" > getMenuInflater</span><span class="pun" >().</span><span class="pln" >inflate</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >menu</span><span class="pun" >.</span><span class="pln" >main</span><span class="pun" >,</span><span class="pln" > menu</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >true</span><span class="pun" >;</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >Following will be the content of<b >res/layout/activity_main.xml</b>file:</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/tools&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >&quot;MainActivity&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView1&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Sending SMS Example&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentTop</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;30dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Tutorials point &quot;</span><span class="pln" > </span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >&quot;#ff87ff09&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;30dp&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView1&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignRight</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignEnd</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;ImageButton</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="atn" >android:src</span><span class="pun" >=</span><span class="atv" >&quot;@drawable/abc&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;EditText</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/editText&quot;</span><span class="pln" > </span><span class="atn" >android:hint</span><span class="pun" >=</span><span class="atv" >&quot;Enter Phone Number&quot;</span><span class="pln" > </span><span class="atn" >android:phoneNumber</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textColorHint</span><span class="pun" >=</span><span class="atv" >&quot;@color/abc_primary_text_material_dark&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;EditText</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/editText2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/editText&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignLeft</span><span class="pun" >=</span><span class="atv" >&quot;@+id/editText&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignStart</span><span class="pun" >=</span><span class="atv" >&quot;@+id/editText&quot;</span><span class="pln" > </span><span class="atn" >android:textColorHint</span><span class="pun" >=</span><span class="atv" >&quot;@color/abc_primary_text_material_dark&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignRight</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignEnd</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="atn" >android:hint</span><span class="pun" >=</span><span class="atv" >&quot;Enter SMS&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Send Sms&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/btnSendSMS&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/editText2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >&quot;48dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/RelativeLayout&gt;</span></pre> <p >Following will be the content of<b >res/values/strings.xml</b>to define two new constants &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;resources&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;app_name&quot;</span><span class="tag" >&gt;</span><span class="pln" >tutorialspoint</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;action_settings&quot;</span><span class="tag" >&gt;</span><span class="pln" >Settings</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;/resources&gt;</span></pre> <p >Following is the default content of<b >AndroidManifest.xml</b>:</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >&quot;com.example.tutorialspoint&quot;</span><span class="pln" > </span><span class="atn" >android:versionCode</span><span class="pun" >=</span><span class="atv" >&quot;1&quot;</span><span class="pln" > </span><span class="atn" >android:versionName</span><span class="pun" >=</span><span class="atv" >&quot;1.0&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;uses-sdk</span><span class="pln" > </span><span class="atn" >android:minSdkVersion</span><span class="pun" >=</span><span class="atv" >&quot;8&quot;</span><span class="pln" > </span><span class="atn" >android:targetSdkVersion</span><span class="pun" >=</span><span class="atv" >&quot;22&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;uses-permission</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.permission.SEND_SMS&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;application</span><span class="pln" > </span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >&quot;@drawable/ic_launcher&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >&quot;@style/AppTheme&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;activity</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;com.example.tutorialspoint.MainActivity&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.action.MAIN&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;category</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.category.LAUNCHER&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;/activity&gt;</span><span class="pln" > </span><span class="tag" >&lt;/application&gt;</span><span class="pln" > </span><span class="tag" >&lt;/manifest&gt;</span></pre> <p >Let&#39;s try to run your<b >tutorialspoint</b>application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Android studio, open one of your project&#39;s activity files and click Run<img alt="Eclipse Run Icon" class="inline" src="http://www.tutorialspoint.com/android/images/eclipse_run.jpg" />icon from the toolbar. Before starting your application, Android studio installer will display following window to select an option where you want to run your Android application.</p> <p><img alt="Android Mobile Device" src="http://www.tutorialspoint.com/android/images/android_mobile_devices.jpg" /></p> <p >Now you can enter a desired mobile number and a text message to be sent on that number. Finally click on<b >Send SMS</b>button to send your SMS. Make sure your GSM/CDMA connection is working fine to deliver your SMS to its recipient.</p> <p >You can take a number of SMS separated by comma and then inside your program you will have to parse them into an array string and finally you can use a loop to send message to all the given numbers. That&#39;s how you can write your own SMS client. Next section will show you how to use existing SMS client to send SMS.</p> <h2 >Using Built-in Intent to send SMS</h2> <p >You can use Android Intent to send SMS by calling built-in SMS functionality of the Android. Following section explains different parts of our Intent object required to send an SMS.</p> <h2 >Intent Object - Action to send SMS</h2> <p >You will use<b >ACTION_VIEW</b>action to launch an SMS client installed on your Android device. Following is simple syntax to create an intent with ACTION_VIEW action</p> <pre class="result notranslate" > Intent smsIntent = new Intent(Intent.ACTION_VIEW); </pre> <h2 >Intent Object - Data/Type to send SMS</h2> <p >To send an SMS you need to specify<b >smsto:</b>as URI using setData() method and data type will be to<b >vnd.android-dir/mms-sms</b>using setType() method as follows &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pln" >smsIntent</span><span class="pun" >.</span><span class="pln" >setData</span><span class="pun" >(</span><span class="typ" >Uri</span><span class="pun" >.</span><span class="pln" >parse</span><span class="pun" >(</span><span class="str" >&quot;smsto:&quot;</span><span class="pun" >));</span><span class="pln" > smsIntent</span><span class="pun" >.</span><span class="pln" >setType</span><span class="pun" >(</span><span class="str" >&quot;vnd.android-dir/mms-sms&quot;</span><span class="pun" >);</span></pre> <h2 >Intent Object - Extra to send SMS</h2> <p >Android has built-in support to add phone number and text message to send an SMS as follows &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pln" >smsIntent</span><span class="pun" >.</span><span class="pln" >putExtra</span><span class="pun" >(</span><span class="str" >&quot;address&quot;</span><span class="pln" > </span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >(</span><span class="str" >&quot;0123456789;3393993300&quot;</span><span class="pun" >));</span><span class="pln" > smsIntent</span><span class="pun" >.</span><span class="pln" >putExtra</span><span class="pun" >(</span><span class="str" >&quot;sms_body&quot;</span><span class="pln" > </span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;Test SMS to Angilla&quot;</span><span class="pun" >);</span></pre> <blockquote >Here address and sms_body are case sensitive and should be specified in small characters only. You can specify more than one number in single string but separated by semi-colon (;).</blockquote> <h2 >Example</h2> <p >Following example shows you in practical how to use Intent object to launch SMS client to send an SMS to the given recipients.</p> <blockquote >To experiment with this example, you will need actual Mobile device equipped with latest Android OS, otherwise you will have to struggle with emulator which may not work.</blockquote> <table class="table table-bordered" > <tbody > <tr > <th class="fivepct" >Step</th> <th >Description</th> </tr> <tr > <td >1</td> <td >You will use Android studio IDE to create an Android application and name it as<i >tutorialspoint</i>under a package<i >com.example.tutorialspoint</i>. While creating this project, make sure you<i >Target SDK</i>and<i >Compile With</i>at the latest version of Android SDK to use higher levels of APIs.</td> </tr> <tr > <td >2</td> <td >Modify<i >src/MainActivity.java</i>file and add required code to take care of sending SMS.</td> </tr> <tr > <td >3</td> <td >Modify layout XML file<i >res/layout/activity_main.xml</i>add any GUI component if required. I&#39;m adding a simple button to launch SMS Client.</td> </tr> <tr > <td >4</td> <td >No need to define default constants.Android studio takes care of default constants.</td> </tr> <tr > <td >5</td> <td >Modify<i >AndroidManifest.xml</i>as shown below</td> </tr> <tr > <td >6</td> <td >Run the application to launch Android emulator and verify the result of the changes done in the application.</td> </tr> </tbody> </table> <p >Following is the content of the modified main activity file<b >src/com.example.tutorialspoint/MainActivity.java</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >package</span><span class="pln" > com</span><span class="pun" >.</span><span class="pln" >example</span><span class="pun" >.</span><span class="pln" >tutorialspoint</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >net</span><span class="pun" >.</span><span class="typ" >Uri</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >os</span><span class="pun" >.</span><span class="typ" >Bundle</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >Activity</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >content</span><span class="pun" >.</span><span class="typ" >Intent</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >util</span><span class="pun" >.</span><span class="typ" >Log</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >Menu</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >View</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Button</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Toast</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >class</span><span class="pln" > </span><span class="typ" >MainActivity</span><span class="pln" > </span><span class="kwd" >extends</span><span class="pln" > </span><span class="typ" >Activity</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onCreate</span><span class="pun" >(</span><span class="typ" >Bundle</span><span class="pln" > savedInstanceState</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onCreate</span><span class="pun" >(</span><span class="pln" >savedInstanceState</span><span class="pun" >);</span><span class="pln" > setContentView</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >activity_main</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >Button</span><span class="pln" > startBtn </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button</span><span class="pun" >);</span><span class="pln" > startBtn</span><span class="pun" >.</span><span class="pln" >setOnClickListener</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >View</span><span class="pun" >.</span><span class="typ" >OnClickListener</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onClick</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > sendSMS</span><span class="pun" >();</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >});</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > sendSMS</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Log</span><span class="pun" >.</span><span class="pln" >i</span><span class="pun" >(</span><span class="str" >&quot;Send SMS&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pln" > smsIntent </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pun" >(</span><span class="typ" >Intent</span><span class="pun" >.</span><span class="pln" >ACTION_VIEW</span><span class="pun" >);</span><span class="pln" > smsIntent</span><span class="pun" >.</span><span class="pln" >setData</span><span class="pun" >(</span><span class="typ" >Uri</span><span class="pun" >.</span><span class="pln" >parse</span><span class="pun" >(</span><span class="str" >&quot;smsto:&quot;</span><span class="pun" >));</span><span class="pln" > smsIntent</span><span class="pun" >.</span><span class="pln" >setType</span><span class="pun" >(</span><span class="str" >&quot;vnd.android-dir/mms-sms&quot;</span><span class="pun" >);</span><span class="pln" > smsIntent</span><span class="pun" >.</span><span class="pln" >putExtra</span><span class="pun" >(</span><span class="str" >&quot;address&quot;</span><span class="pln" > </span><span class="pun" >,</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pln" > </span><span class="pun" >(</span><span class="str" >&quot;01234&quot;</span><span class="pun" >));</span><span class="pln" > smsIntent</span><span class="pun" >.</span><span class="pln" >putExtra</span><span class="pun" >(</span><span class="str" >&quot;sms_body&quot;</span><span class="pln" > </span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;Test &quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >try</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > startActivity</span><span class="pun" >(</span><span class="pln" >smsIntent</span><span class="pun" >);</span><span class="pln" > finish</span><span class="pun" >();</span><span class="pln" > </span><span class="typ" >Log</span><span class="pun" >.</span><span class="pln" >i</span><span class="pun" >(</span><span class="str" >&quot;Finished sending SMS...&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >catch</span><span class="pln" > </span><span class="pun" >(</span><span class="pln" >android</span><span class="pun" >.</span><span class="pln" >content</span><span class="pun" >.</span><span class="typ" >ActivityNotFoundException</span><span class="pln" > ex</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >makeText</span><span class="pun" >(</span><span class="typ" >MainActivity</span><span class="pun" >.</span><span class="kwd" >this</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;SMS faild, please try again later.&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >LENGTH_SHORT</span><span class="pun" >).</span><span class="pln" >show</span><span class="pun" >();</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >boolean</span><span class="pln" > onCreateOptionsMenu</span><span class="pun" >(</span><span class="typ" >Menu</span><span class="pln" > menu</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="com" >// Inflate the menu; this adds items to the action bar if it is present.</span><span class="pln" > getMenuInflater</span><span class="pun" >().</span><span class="pln" >inflate</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >menu</span><span class="pun" >.</span><span class="pln" >main</span><span class="pun" >,</span><span class="pln" > menu</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >true</span><span class="pun" >;</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >Following will be the content of<b >res/layout/activity_main.xml</b>file &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/tools&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >&quot;.MainActivity&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Drag and Drop Example&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentTop</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;30dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Tutorials Point &quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;30dp&quot;</span><span class="pln" > </span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >&quot;#ff14be3c&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;ImageView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageView&quot;</span><span class="pln" > </span><span class="atn" >android:src</span><span class="pun" >=</span><span class="atv" >&quot;@drawable/abc&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >&quot;48dp&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Compose SMS&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignRight</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignEnd</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >&quot;54dp&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignLeft</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignStart</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageView&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/RelativeLayout&gt;</span></pre> <p >Following will be the content of<b >res/values/strings.xml</b>to define two new constants &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;resources&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;app_name&quot;</span><span class="tag" >&gt;</span><span class="pln" >tutorialspoint</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;action_settings&quot;</span><span class="tag" >&gt;</span><span class="pln" >Settings</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;/resources&gt;</span></pre> <p >Following is the default content of<b >AndroidManifest.xml</b>&minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >&quot;com.example.tutorialspoint&quot;</span><span class="pln" > </span><span class="atn" >android:versionCode</span><span class="pun" >=</span><span class="atv" >&quot;1&quot;</span><span class="pln" > </span><span class="atn" >android:versionName</span><span class="pun" >=</span><span class="atv" >&quot;1.0&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;uses-sdk</span><span class="pln" > </span><span class="atn" >android:minSdkVersion</span><span class="pun" >=</span><span class="atv" >&quot;8&quot;</span><span class="pln" > </span><span class="atn" >android:targetSdkVersion</span><span class="pun" >=</span><span class="atv" >&quot;22&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;application</span><span class="pln" > </span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >&quot;@drawable/ic_launcher&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >&quot;@style/AppTheme&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;activity</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;com.example.tutorialspoint.MainActivity&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.action.MAIN&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;category</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.category.LAUNCHER&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;/activity&gt;</span><span class="pln" > </span><span class="tag" >&lt;/application&gt;</span><span class="pln" > </span><span class="tag" >&lt;/manifest&gt;</span></pre> <p >Let&#39;s try to run your<b >tutorialspoint</b>application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Android studio, open one of your project&#39;s activity files and click Run<img alt="Eclipse Run Icon" class="inline" src="http://www.tutorialspoint.com/android/images/eclipse_run.jpg" />icon from the toolbar. Before starting your application, Android studio will display following window to select an option where you want to run your Android application.</p> <p><img alt="Android Mobile Device" src="http://www.tutorialspoint.com/android/images/android_mobile_device1.jpg" /></p> <p >Select your mobile device as an option and then check your mobile device which will display following screen:</p> <p><img alt="Android Mobile SMS Compose" src="http://www.tutorialspoint.com/android/images/mobile_sms_compose.jpg" /></p> <p >Now use<b >Compose SMS</b>button to launch Android built-in SMS clients which is shown below:</p> <p><img alt="Android Mobile SMS Screen" src="http://www.tutorialspoint.com/android/images/mobile_sms_screen.jpg" /></p> <p >You can modify either of the given default fields and finally use send SMS button to send your SMS to the mentioned recipient.</p> <script language="vbscript" type="text/javascript"> <br /> < !-- <br /> Option Explicit 要求在脚本中声明所有的变量 <br /> Dim Mystring <br /> Mystring="This is my string" <br /> -- > <br /> < /script><br /> </body></html></script>
T:0.009223s,M:267.48 KB
返回顶部 留言