{"id":7635,"date":"2013-12-20T12:00:51","date_gmt":"2013-12-20T10:00:51","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=7635"},"modified":"2013-12-19T21:33:10","modified_gmt":"2013-12-19T19:33:10","slug":"android-sending-sms-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/","title":{"rendered":"Android Sending SMS Example"},"content":{"rendered":"<p>In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing:<\/p>\n<ul>\n<li>By using <a href=\"http:\/\/developer.android.com\/reference\/android\/telephony\/SmsManager.html\" target=\"_blank\"><code>SmsManager<\/code><\/a> class<\/li>\n<li>By using an <code>implicit <a href=\"http:\/\/developer.android.com\/reference\/android\/content\/Intent.html\" target=\"_blank\">Intent<\/a><\/code><\/li>\n<\/ul>\n<p>The use of <code>SmsManager<\/code> facilitates the sms sending because it gives us the opportunity to customize this functionality with the manner we want, within our own <code>Activity<\/code>. In parallel, the use of <code>Intents<\/code> implies the use of built-in applications and sms clients that are installed in each Android device. In this example, we are going to implement both ways. More specifically, we are going to send a sms by using <code>SmsManager<\/code> and <code>implicit Intent<\/code> with <code>SENDTO<\/code> action and\/or <code>VIEW<\/code> action.<\/p>\n<p>For this tutorial, we will use the following tools in a Windows 64-bit platform:<\/p>\n<ol>\n<li>JDK 1.7<\/li>\n<li>Eclipse 4.2 Juno<\/li>\n<li>Android SDK 4.4<\/li>\n<\/ol>\n<h2>1. Create a New Android Application Project<\/h2>\n<p>Open Eclipse IDE and go to File \u2192 New \u2192 Project \u2192 Android Application Project.<\/p>\n<p>Specify the name of the application, the project and the package in the appropriate fields. Then click Next.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1.png\" alt=\"sendSmsProj1\" width=\"507\" height=\"509\" class=\"alignnone size-full wp-image-7637\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1.png 507w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1-150x150.png 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1-298x300.png 298w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1-200x200.png 200w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1-100x100.png 100w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj1-42x42.png 42w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/a><\/p>\n<p>In the next window, choose the \u201cCreate Activity\u201d check-option. The new created activity will be the main activity of your project. Then press Next button. <\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2.png\" alt=\"sendSmsProj2\" width=\"507\" height=\"509\" class=\"alignnone size-full wp-image-7638\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2.png 507w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2-150x150.png 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2-298x300.png 298w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2-200x200.png 200w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2-100x100.png 100w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsProj2-42x42.png 42w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/a><\/p>\n<p>In \u201cConfigure Launcher Icon\u201d window you should choose the icon you want to have in your app. We will use the default icon of android, so click Next. <\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject3.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject3.png\" alt=\"createProject3!\" width=\"563\" height=\"572\" class=\"alignnone size-full wp-image-7274\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject3.png 563w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject3-295x300.png 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject3-42x42.png 42w\" sizes=\"(max-width: 563px) 100vw, 563px\" \/><\/a><\/p>\n<p>Select the \u201cBlank Activity\u201d option and press Next. <\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject4.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject4.png\" alt=\"createProject4!\" width=\"563\" height=\"572\" class=\"alignnone size-full wp-image-7275\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject4.png 563w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject4-295x300.png 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject4-42x42.png 42w\" sizes=\"(max-width: 563px) 100vw, 563px\" \/><\/a><\/p>\n<p>Specify a name for the new Activity and a name for the layout description of your app. The .xml file for the layout will automatically be created in the\u00a0<code>res\/layout<\/code>\u00a0folder. Finally, press Finish. <\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject5.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject5.png\" alt=\"createProject5!\" width=\"522\" height=\"555\" class=\"alignnone size-full wp-image-7276\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject5.png 522w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/createProject5-282x300.png 282w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/a><\/p>\n<p>Now, you can see the structure of your created project.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsStructure.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/sendSmsStructure.png\" alt=\"sendSmsStructure\" width=\"343\" height=\"585\" class=\"alignnone size-full wp-image-7639\" \/><\/a><\/p>\n<h2>2. Create the layout of the Main Activity<\/h2>\n<p>We will put two <code>EditTexts<\/code> so that the user can fill in a phone number and a message for a SMS. Also, we are going to add three different <code>Buttons<\/code>, that each one enables a different action and uses a suitable class (<code>smsManager<\/code>, <code>Intent<\/code> with <code>SENDTO<\/code> action, <code>Intent<\/code> with <code>VIEW<\/code> action).<\/p>\n<p>Open <code>res\/layout\/activity_main.xml<\/code> and go to the respective xml tab. Then paste the following.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><em><u>activity_main.xml:<\/u><\/em><\/p>\n<pre class=\"brush:xml\">\r\n&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:id=\"@+id\/linearLayout1\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"fill_parent\"\r\n    android:orientation=\"vertical\" &gt;\r\n\r\n    &lt;TextView\r\n        android:id=\"@+id\/text\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Complete the fields to send a sms\"\r\n        android:textAppearance=\"?android:attr\/textAppearanceMedium\" \/&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/phoneNumber\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:ems=\"10\"\r\n        android:hint=\"ex: 1234567890\"\r\n        android:inputType=\"phone\" \/&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/smsBody\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"80dp\"\r\n        android:layout_marginBottom=\"30dp\"\r\n        android:hint=\"Write your sms here....\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/smsManager\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Send the sms by SmsManager\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/smsSIntent\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Send the sms by SENDTO\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/smsVIntent\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Send the sms by VIEW\" \/&gt;\r\n\r\n&lt;\/LinearLayout&gt;\r\n<\/pre>\n<h2>3. Code the Main Activity<\/h2>\n<p><code>SmsManager<\/code> handles SMS operations and <code>getDefault()<\/code> method should be called, in order to get an instance of this object. For the intent with <code>ACTION_SENDTO<\/code> we have to define the data as <code>smsto:<\/code> and the phone number added at the end. Respectively, for the intent with <code>ACTION_VIEW<\/code> we will define the type as <code>vnd.android-dir\/mms-sms<\/code>, so only sms-mms providers will launch. Also, we have to add the phone number and the message as extra fields to that intent.<\/p>\n<p>Open <code>src\/com.javacodegeeks.android.sendsmstest\/MainActivity.java<\/code> and paste the following.<\/p>\n<p><em><u>MainActivity.java:<\/u><\/em><\/p>\n<pre class=\"brush:java\">\r\npackage com.javacodegeeks.android.sendsmstest;\r\n\r\nimport android.app.Activity;\r\nimport android.content.Intent;\r\nimport android.net.Uri;\r\nimport android.os.Bundle;\r\nimport android.telephony.SmsManager;\r\nimport android.view.View;\r\nimport android.view.View.OnClickListener;\r\nimport android.widget.Button;\r\nimport android.widget.EditText;\r\nimport android.widget.Toast;\r\n\r\npublic class MainActivity extends Activity {\r\n\r\n\tprivate EditText phoneNumber;\r\n\tprivate EditText smsBody;\r\n\tprivate Button smsManagerBtn;\r\n\tprivate Button smsSendToBtn;\r\n\tprivate Button smsViewBtn;\r\n\r\n\t@Override\r\n\tpublic void onCreate(Bundle savedInstanceState) {\r\n\t\tsuper.onCreate(savedInstanceState);\r\n\t\tsetContentView(R.layout.activity_main);\r\n\r\n\t\tphoneNumber = (EditText) findViewById(R.id.phoneNumber);\r\n\t\tsmsBody = (EditText) findViewById(R.id.smsBody);\r\n\t\tsmsManagerBtn = (Button) findViewById(R.id.smsManager);\r\n\t\tsmsSendToBtn = (Button) findViewById(R.id.smsSIntent);\r\n\t\tsmsViewBtn = (Button) findViewById(R.id.smsVIntent);\r\n\r\n\t\tsmsManagerBtn.setOnClickListener(new OnClickListener() {\r\n\t\t\t public void onClick(View view) {\r\n\t\t\t\t sendSmsByManager();\r\n\t\t\t }\r\n\t\t});\r\n\t\t\r\n\t\tsmsSendToBtn.setOnClickListener(new OnClickListener() {\r\n\t\t\t public void onClick(View view) {\r\n\t\t\t\t sendSmsBySIntent();\r\n\t\t\t }\r\n\t\t});\r\n\t\t\r\n\t\tsmsViewBtn.setOnClickListener(new OnClickListener() {\r\n\t\t\t public void onClick(View view) {\r\n\t\t\t\t sendSmsByVIntent();\r\n\t\t\t }\r\n\t\t});\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic void sendSmsByManager() {\r\n\t\ttry {\r\n\t\t\t\/\/ Get the default instance of the SmsManager\r\n\t\t\tSmsManager smsManager = SmsManager.getDefault();\r\n\t\t\tsmsManager.sendTextMessage(phoneNumber.getText().toString(), \r\n\t\t\t\t\tnull,  \r\n\t\t\t\t\tsmsBody.getText().toString(), \r\n\t\t\t\t\tnull, \r\n\t\t\t\t\tnull);\r\n\t\t\tToast.makeText(getApplicationContext(), \"Your sms has successfully sent!\",\r\n\t\t\t\t\tToast.LENGTH_LONG).show();\r\n\t\t} catch (Exception ex) {\r\n\t\t\tToast.makeText(getApplicationContext(),\"Your sms has failed...\",\r\n\t\t\t\t\tToast.LENGTH_LONG).show();\r\n\t\t\tex.printStackTrace();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void sendSmsBySIntent() {\r\n\t\t\/\/ add the phone number in the data\r\n\t\tUri uri = Uri.parse(\"smsto:\" + phoneNumber.getText().toString());\r\n\t\t\r\n\t\tIntent smsSIntent = new Intent(Intent.ACTION_SENDTO, uri);\r\n\t\t\/\/ add the message at the sms_body extra field\r\n\t\tsmsSIntent.putExtra(\"sms_body\", smsBody.getText().toString());\r\n\t\ttry{\r\n\t\t\tstartActivity(smsSIntent);\r\n\t\t} catch (Exception ex) {\r\n\t\t\tToast.makeText(MainActivity.this, \"Your sms has failed...\",\r\n\t\t\t\t\tToast.LENGTH_LONG).show();\r\n\t\t\tex.printStackTrace();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void sendSmsByVIntent() {\r\n\t\t\r\n\t\tIntent smsVIntent = new Intent(Intent.ACTION_VIEW);\r\n\t\t\/\/ prompts only sms-mms clients\r\n\t\tsmsVIntent.setType(\"vnd.android-dir\/mms-sms\");\r\n\t\t\r\n\t\t\/\/ extra fields for number and message respectively\r\n\t\tsmsVIntent.putExtra(\"address\", phoneNumber.getText().toString());\r\n\t\tsmsVIntent.putExtra(\"sms_body\", smsBody.getText().toString());\r\n\t\ttry{\r\n\t\t\tstartActivity(smsVIntent);\r\n\t\t} catch (Exception ex) {\r\n\t\t\tToast.makeText(MainActivity.this, \"Your sms has failed...\",\r\n\t\t\t\t\tToast.LENGTH_LONG).show();\r\n\t\t\tex.printStackTrace();\r\n\t\t}\r\n\r\n\t}\r\n}\r\n<\/pre>\n<h2>4. Set the SMS\u00a0Permission<\/h2>\n<p>We should set <code>SEND_SMS<\/code> as permission in the <code>AndroidManifest.xml<\/code> file, in order to send an SMS via our application. At this point, we should mention that the permission must be defined for <code>smsManager<\/code>, but it is not necessary for the <code>implicit Intents<\/code>.<\/p>\n<p>Open <code>AndroidManifest.xml<\/code> file and go to the respective xml tab. Then paste the permission <code>android.permission.SEND_SMS<\/code>, as you can see below.<\/p>\n<p><em><u>AndroidManifest.xml:<\/u><\/em><\/p>\n<pre class=\"brush:xml\">\r\n&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    package=\"com.javacodegeeks.android.sendsmstest\"\r\n    android:versionCode=\"1\"\r\n    android:versionName=\"1.0\" &gt;\r\n\r\n    &lt;uses-sdk\r\n        android:minSdkVersion=\"8\"\r\n        android:targetSdkVersion=\"19\" \/&gt;\r\n    \r\n    &lt;uses-permission android:name=\"android.permission.SEND_SMS\" \/&gt;\r\n\r\n    &lt;application\r\n        android:allowBackup=\"true\"\r\n        android:icon=\"@drawable\/ic_launcher\"\r\n        android:label=\"@string\/app_name\"\r\n        android:theme=\"@style\/AppTheme\" &gt;\r\n        &lt;activity\r\n            android:name=\"com.javacodegeeks.android.sendsmstest.MainActivity\"\r\n            android:label=\"@string\/app_name\" &gt;\r\n            &lt;intent-filter&gt;\r\n                &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\r\n\r\n                &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\r\n            &lt;\/intent-filter&gt;\r\n        &lt;\/activity&gt;\r\n    &lt;\/application&gt;\r\n\r\n&lt;\/manifest&gt;\r\n<\/pre>\n<h2>5. Run the application<\/h2>\n<p>To run our application, right click on our project \u2192 Run as \u2192 Android Application. The AVD will appear with the app loaded.<\/p>\n<p>Fill in a phone number and a message in order to send a sms, as shown in the picture below.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj1.png\" alt=\"ADVSmsProj1\" width=\"256\" height=\"359\" class=\"alignnone size-full wp-image-7643\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj1.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj1-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>Lets press &#8220;Send the sms by SmsManager&#8221; button. The sms will be sent via <code>smsManager<\/code>, so a <code>Toast<\/code> will appear which certify the success of sms sending. Otherwise, an error message would be appeared.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj2.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj2.png\" alt=\"ADVSmsProj2\" width=\"256\" height=\"359\" class=\"alignnone size-full wp-image-7644\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj2.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj2-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>Now press the &#8220;Send the sms by SENDTO&#8221; button. If more than one applications, that use a <code>SENDTO<\/code> action exist, the user will choose one of the displayed ones. For example, our emulator contains an application that uses an implicit intent with <code>ACTION_SENDTO<\/code>, as shown in the picture. <\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj3.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj3.png\" alt=\"ADVSmsProj3\" width=\"256\" height=\"359\" class=\"alignnone size-full wp-image-7645\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj3.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj3-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a> <\/p>\n<p>Lets choose the default Android app for sms. As you can see in the picture below, the fields are completed with the elements that the user gave previously.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj4.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj4.png\" alt=\"ADVSmsProj4\" width=\"256\" height=\"359\" class=\"alignnone size-full wp-image-7646\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj4.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/ADVSmsProj4-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>Finally if we press the &#8220;Send the sms by VIEW&#8221; button, the device\u2019s\u00a0Built-in SMS\u00a0application will launch with the appropriate fields filled in, same as shown in the image above.<\/p>\n<h2>Download Eclipse Project<\/h2>\n<p>This was an example of sending a sms in Android. Download the Eclipse Project of this example: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/SendSMSTest.zip\">SendSMSTest.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing: By using SmsManager class By using an implicit Intent The use of SmsManager facilitates the sms sending because it gives us the opportunity to customize this functionality with the manner we &hellip;<\/p>\n","protected":false},"author":11,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[336],"tags":[504],"class_list":["post-7635","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smsmanager","tag-implicit-intent"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android Sending SMS Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing: By using SmsManager\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Sending SMS Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing: By using SmsManager\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-12-20T10:00:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Katerina Zamani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Katerina Zamani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/\"},\"author\":{\"name\":\"Katerina Zamani\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\"},\"headline\":\"Android Sending SMS Example\",\"datePublished\":\"2013-12-20T10:00:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/\"},\"wordCount\":678,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"keywords\":[\"implicit Intent\"],\"articleSection\":[\"SmsManager\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/\",\"name\":\"Android Sending SMS Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2013-12-20T10:00:51+00:00\",\"description\":\"In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing: By using SmsManager\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"telephony\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/telephony\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SmsManager\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/telephony\/smsmanager\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Android Sending SMS Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\",\"name\":\"Katerina Zamani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"caption\":\"Katerina Zamani\"},\"description\":\"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Sending SMS Example - Java Code Geeks","description":"In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing: By using SmsManager","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/","og_locale":"en_US","og_type":"article","og_title":"Android Sending SMS Example - Java Code Geeks","og_description":"In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing: By using SmsManager","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-12-20T10:00:51+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Katerina Zamani","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Katerina Zamani","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/"},"author":{"name":"Katerina Zamani","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673"},"headline":"Android Sending SMS Example","datePublished":"2013-12-20T10:00:51+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/"},"wordCount":678,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","keywords":["implicit Intent"],"articleSection":["SmsManager"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/","name":"Android Sending SMS Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2013-12-20T10:00:51+00:00","description":"In some situations, we want to send sms messages from our own Android application. There are two different ways to do such a thing: By using SmsManager","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/telephony\/smsmanager\/android-sending-sms-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"telephony","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/telephony\/"},{"@type":"ListItem","position":5,"name":"SmsManager","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/telephony\/smsmanager\/"},{"@type":"ListItem","position":6,"name":"Android Sending SMS Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673","name":"Katerina Zamani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","caption":"Katerina Zamani"},"description":"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/7635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=7635"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/7635\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=7635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=7635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=7635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}