<p >In Android, you can use SmsManager API or devices Built-in SMS application to send SMS's. In this tutorial, we shows you two basic examples to send SMS message −</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" >"phoneNo"</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" >"sms 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></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" >"sms_body"</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >"default content"</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" >"vnd.android-dir/mms-sms"</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" ><uses-permission</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.permission.SEND_SMS"</span><span class="pln" > </span><span class="tag" >/></span></pre>
<p >Apart from the above method, there are few other important functions available in SmsManager class. These methods are listed below −</p>
<table class="table table-bordered" >
<tbody >
<tr >
<th >Sr.No.</th>
<th >Method & Description</th>
</tr>
<tr >
<td >1</td>
<td ><b >ArrayList<String> 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<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> 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'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" >"Send SMS"</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >""</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" >"SMS sent."</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" >"SMS faild, please try again."</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" ><RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/apk/res/android"</span><span class="pln" >
</span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/tools"</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"match_parent"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"match_parent"</span><span class="pln" >
</span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_vertical_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_horizontal_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_horizontal_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_vertical_margin"</span><span class="pln" >
</span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >"MainActivity"</span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><TextView</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/textView1"</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Sending SMS Example"</span><span class="pln" >
</span><span class="atn" >android:layout_alignParentTop</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >"30dp"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><TextView</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/textView2"</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Tutorials point "</span><span class="pln" >
</span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >"#ff87ff09"</span><span class="pln" >
</span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >"30dp"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/textView1"</span><span class="pln" >
</span><span class="atn" >android:layout_alignRight</span><span class="pun" >=</span><span class="atv" >"@+id/imageButton"</span><span class="pln" >
</span><span class="atn" >android:layout_alignEnd</span><span class="pun" >=</span><span class="atv" >"@+id/imageButton"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><ImageButton</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/imageButton"</span><span class="pln" >
</span><span class="atn" >android:src</span><span class="pun" >=</span><span class="atv" >"@drawable/abc"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/textView2"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><EditText</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/editText"</span><span class="pln" >
</span><span class="atn" >android:hint</span><span class="pun" >=</span><span class="atv" >"Enter Phone Number"</span><span class="pln" >
</span><span class="atn" >android:phoneNumber</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:textColorHint</span><span class="pun" >=</span><span class="atv" >"@color/abc_primary_text_material_dark"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/imageButton"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><EditText</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/editText2"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/editText"</span><span class="pln" >
</span><span class="atn" >android:layout_alignLeft</span><span class="pun" >=</span><span class="atv" >"@+id/editText"</span><span class="pln" >
</span><span class="atn" >android:layout_alignStart</span><span class="pun" >=</span><span class="atv" >"@+id/editText"</span><span class="pln" >
</span><span class="atn" >android:textColorHint</span><span class="pun" >=</span><span class="atv" >"@color/abc_primary_text_material_dark"</span><span class="pln" >
</span><span class="atn" >android:layout_alignRight</span><span class="pun" >=</span><span class="atv" >"@+id/imageButton"</span><span class="pln" >
</span><span class="atn" >android:layout_alignEnd</span><span class="pun" >=</span><span class="atv" >"@+id/imageButton"</span><span class="pln" >
</span><span class="atn" >android:hint</span><span class="pun" >=</span><span class="atv" >"Enter SMS"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><Button</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Send Sms"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/btnSendSMS"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/editText2"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >"48dp"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ></RelativeLayout></span></pre>
<p >Following will be the content of<b >res/values/strings.xml</b>to define two new constants −</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="pun" ><?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >"1.0"</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >"utf-8"</span><span class="pun" >?></span><span class="pln" >
</span><span class="tag" ><resources></span><span class="pln" >
</span><span class="tag" ><string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >"app_name"</span><span class="tag" >></span><span class="pln" >tutorialspoint</span><span class="tag" ></string></span><span class="pln" >
</span><span class="tag" ><string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >"action_settings"</span><span class="tag" >></span><span class="pln" >Settings</span><span class="tag" ></string></span><span class="pln" >
</span><span class="tag" ></resources></span></pre>
<p >Following is the default content of<b >AndroidManifest.xml</b>:</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="pun" ><?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >"1.0"</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >"utf-8"</span><span class="pun" >?></span><span class="pln" >
</span><span class="tag" ><manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/apk/res/android"</span><span class="pln" >
</span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >"com.example.tutorialspoint"</span><span class="pln" >
</span><span class="atn" >android:versionCode</span><span class="pun" >=</span><span class="atv" >"1"</span><span class="pln" >
</span><span class="atn" >android:versionName</span><span class="pun" >=</span><span class="atv" >"1.0"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><uses-sdk</span><span class="pln" >
</span><span class="atn" >android:minSdkVersion</span><span class="pun" >=</span><span class="atv" >"8"</span><span class="pln" >
</span><span class="atn" >android:targetSdkVersion</span><span class="pun" >=</span><span class="atv" >"22"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><uses-permission</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.permission.SEND_SMS"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><application</span><span class="pln" >
</span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >"@drawable/ic_launcher"</span><span class="pln" >
</span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >"@string/app_name"</span><span class="pln" >
</span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >"@style/AppTheme"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><activity</span><span class="pln" >
</span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"com.example.tutorialspoint.MainActivity"</span><span class="pln" >
</span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >"@string/app_name"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><intent-filter></span><span class="pln" >
</span><span class="tag" ><action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.intent.action.MAIN"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><category</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.intent.category.LAUNCHER"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ></intent-filter></span><span class="pln" >
</span><span class="tag" ></activity></span><span class="pln" >
</span><span class="tag" ></application></span><span class="pln" >
</span><span class="tag" ></manifest></span></pre>
<p >Let'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'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'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 −</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" >"smsto:"</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" >"vnd.android-dir/mms-sms"</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 −</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" >"address"</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" >"0123456789;3393993300"</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" >"sms_body"</span><span class="pln" > </span><span class="pun" >,</span><span class="pln" > </span><span class="str" >"Test SMS to Angilla"</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'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" >"Send SMS"</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >""</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" >"smsto:"</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" >"vnd.android-dir/mms-sms"</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" >"address"</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" >"01234"</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" >"sms_body"</span><span class="pln" > </span><span class="pun" >,</span><span class="pln" > </span><span class="str" >"Test "</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" >"Finished sending SMS..."</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >""</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" >"SMS faild, please try again later."</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 −</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="tag" ><RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/apk/res/android"</span><span class="pln" >
</span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/tools"</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"match_parent"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"match_parent"</span><span class="pln" >
</span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_horizontal_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_horizontal_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_vertical_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_vertical_margin"</span><span class="pln" >
</span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >".MainActivity"</span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><TextView</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Drag and Drop Example"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/textView"</span><span class="pln" >
</span><span class="atn" >android:layout_alignParentTop</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >"30dp"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><TextView</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Tutorials Point "</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/textView2"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/textView"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >"30dp"</span><span class="pln" >
</span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >"#ff14be3c"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><ImageView</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/imageView"</span><span class="pln" >
</span><span class="atn" >android:src</span><span class="pun" >=</span><span class="atv" >"@drawable/abc"</span><span class="pln" >
</span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >"48dp"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/textView2"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><Button</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Compose SMS"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/button"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/imageView"</span><span class="pln" >
</span><span class="atn" >android:layout_alignRight</span><span class="pun" >=</span><span class="atv" >"@+id/textView2"</span><span class="pln" >
</span><span class="atn" >android:layout_alignEnd</span><span class="pun" >=</span><span class="atv" >"@+id/textView2"</span><span class="pln" >
</span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >"54dp"</span><span class="pln" >
</span><span class="atn" >android:layout_alignLeft</span><span class="pun" >=</span><span class="atv" >"@+id/imageView"</span><span class="pln" >
</span><span class="atn" >android:layout_alignStart</span><span class="pun" >=</span><span class="atv" >"@+id/imageView"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ></RelativeLayout></span></pre>
<p >Following will be the content of<b >res/values/strings.xml</b>to define two new constants −</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="pun" ><?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >"1.0"</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >"utf-8"</span><span class="pun" >?></span><span class="pln" >
</span><span class="tag" ><resources></span><span class="pln" >
</span><span class="tag" ><string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >"app_name"</span><span class="tag" >></span><span class="pln" >tutorialspoint</span><span class="tag" ></string></span><span class="pln" >
</span><span class="tag" ><string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >"action_settings"</span><span class="tag" >></span><span class="pln" >Settings</span><span class="tag" ></string></span><span class="pln" >
</span><span class="tag" ></resources></span></pre>
<p >Following is the default content of<b >AndroidManifest.xml</b>−</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="pun" ><?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >"1.0"</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >"utf-8"</span><span class="pun" >?></span><span class="pln" >
</span><span class="tag" ><manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/apk/res/android"</span><span class="pln" >
</span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >"com.example.tutorialspoint"</span><span class="pln" >
</span><span class="atn" >android:versionCode</span><span class="pun" >=</span><span class="atv" >"1"</span><span class="pln" >
</span><span class="atn" >android:versionName</span><span class="pun" >=</span><span class="atv" >"1.0"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><uses-sdk</span><span class="pln" >
</span><span class="atn" >android:minSdkVersion</span><span class="pun" >=</span><span class="atv" >"8"</span><span class="pln" >
</span><span class="atn" >android:targetSdkVersion</span><span class="pun" >=</span><span class="atv" >"22"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><application</span><span class="pln" >
</span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >"@drawable/ic_launcher"</span><span class="pln" >
</span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >"@string/app_name"</span><span class="pln" >
</span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >"@style/AppTheme"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><activity</span><span class="pln" >
</span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"com.example.tutorialspoint.MainActivity"</span><span class="pln" >
</span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >"@string/app_name"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><intent-filter></span><span class="pln" >
</span><span class="tag" ><action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.intent.action.MAIN"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><category</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.intent.category.LAUNCHER"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ></intent-filter></span><span class="pln" >
</span><span class="tag" ></activity></span><span class="pln" >
</span><span class="tag" ></application></span><span class="pln" >
</span><span class="tag" ></manifest></span></pre>
<p >Let'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'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>