{"id":27971,"date":"2024-03-16T09:32:08","date_gmt":"2024-03-16T09:32:08","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/"},"modified":"2024-03-22T12:19:27","modified_gmt":"2024-03-22T12:19:27","slug":"implementing-sms-verification-code-function-in-android-development","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/","title":{"rendered":"Implementing SMS verification code function in Android development."},"content":{"rendered":"<p>In Android development, the SMS verification code feature can be implemented by following these steps:<\/p>\n<ol>\n<li>Add permission: Add the following permissions in the AndroidManifest.xml file.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">uses-permission<\/span> <span class=\"hljs-attr\">android:name<\/span>=<span class=\"hljs-string\">\"android.permission.RECEIVE_SMS\"<\/span>\/&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">uses-permission<\/span> <span class=\"hljs-attr\">android:name<\/span>=<span class=\"hljs-string\">\"android.permission.READ_SMS\"<\/span>\/&gt;<\/span>\r\n<\/code><\/pre>\n<ol>\n<li>Create a BroadcastReceiver: Create a class that extends BroadcastReceiver to receive SMS verification codes. Override the onReceive() method in the class, which will be triggered when a SMS is received.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">SMSReceiver<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_\">BroadcastReceiver<\/span>{\r\n\r\n    <span class=\"hljs-meta\">@Override<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">onReceive<\/span><span class=\"hljs-params\">(Context context, Intent intent)<\/span> {\r\n        <span class=\"hljs-type\">Bundle<\/span> <span class=\"hljs-variable\">bundle<\/span> <span class=\"hljs-operator\">=<\/span> intent.getExtras();\r\n        <span class=\"hljs-keyword\">if<\/span> (bundle != <span class=\"hljs-literal\">null<\/span>) {\r\n            Object[] pdus = (Object[]) bundle.get(<span class=\"hljs-string\">\"pdus\"<\/span>);\r\n            <span class=\"hljs-keyword\">if<\/span> (pdus != <span class=\"hljs-literal\">null<\/span>) {\r\n                <span class=\"hljs-keyword\">for<\/span> (Object pdu : pdus) {\r\n                    <span class=\"hljs-type\">SmsMessage<\/span> <span class=\"hljs-variable\">smsMessage<\/span> <span class=\"hljs-operator\">=<\/span> SmsMessage.createFromPdu((<span class=\"hljs-type\">byte<\/span>[]) pdu);\r\n                    <span class=\"hljs-type\">String<\/span> <span class=\"hljs-variable\">messageBody<\/span> <span class=\"hljs-operator\">=<\/span> smsMessage.getMessageBody();\r\n                    <span class=\"hljs-comment\">\/\/ \u5728\u8fd9\u91cc\u5904\u7406\u77ed\u4fe1\u9a8c\u8bc1\u7801<\/span>\r\n                    <span class=\"hljs-comment\">\/\/ \u53ef\u4ee5\u5c06\u77ed\u4fe1\u9a8c\u8bc1\u7801\u53d1\u9001\u7ed9UI\u754c\u9762\u663e\u793a\uff0c\u6216\u8005\u81ea\u52a8\u586b\u5145\u5230\u76f8\u5e94\u7684\u8f93\u5165\u6846\u4e2d<\/span>\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n<ol>\n<li>Register a BroadcastReceiver: In the Activity where you need to receive the SMS verification code, register a BroadcastReceiver. You can register it in the onResume() method and unregister it in the onPause() method.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">private<\/span> SMSReceiver smsReceiver;\r\n\r\n<span class=\"hljs-meta\">@Override<\/span>\r\n<span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">onResume<\/span><span class=\"hljs-params\">()<\/span> {\r\n    <span class=\"hljs-built_in\">super<\/span>.onResume();\r\n    <span class=\"hljs-comment\">\/\/ \u521b\u5efaIntentFilter\u5bf9\u8c61\uff0c\u5e76\u8bbe\u7f6e\u63a5\u6536\u77ed\u4fe1\u7684action<\/span>\r\n    <span class=\"hljs-type\">IntentFilter<\/span> <span class=\"hljs-variable\">intentFilter<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">IntentFilter<\/span>();\r\n    intentFilter.addAction(<span class=\"hljs-string\">\"android.provider.Telephony.SMS_RECEIVED\"<\/span>);\r\n    <span class=\"hljs-comment\">\/\/ \u521b\u5efaBroadcastReceiver\u5bf9\u8c61<\/span>\r\n    smsReceiver = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">SMSReceiver<\/span>();\r\n    <span class=\"hljs-comment\">\/\/ \u6ce8\u518creceiver<\/span>\r\n    registerReceiver(smsReceiver, intentFilter);\r\n}\r\n\r\n<span class=\"hljs-meta\">@Override<\/span>\r\n<span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">onPause<\/span><span class=\"hljs-params\">()<\/span> {\r\n    <span class=\"hljs-built_in\">super<\/span>.onPause();\r\n    <span class=\"hljs-comment\">\/\/ \u53d6\u6d88\u6ce8\u518creceiver<\/span>\r\n    unregisterReceiver(smsReceiver);\r\n}\r\n<\/code><\/pre>\n<p>By following the steps above, you can implement SMS verification functionality in an Android application. When receiving a SMS, the BroadcastReceiver will trigger the onReceive() method, allowing you to handle the SMS verification. For example, you can display the verification code on the UI interface, or automatically fill it in the relevant input field.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Android development, the SMS verification code feature can be implemented by following these steps: Add permission: Add the following permissions in the AndroidManifest.xml file. &lt;uses-permission android:name=&#8221;android.permission.RECEIVE_SMS&#8221;\/&gt; &lt;uses-permission android:name=&#8221;android.permission.READ_SMS&#8221;\/&gt; Create a BroadcastReceiver: Create a class that extends BroadcastReceiver to receive SMS verification codes. Override the onReceive() method in the class, which will be triggered when [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-27971","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Implementing SMS verification code function in Android development. - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Implementing SMS verification code function in Android development.\" \/>\n<meta property=\"og:description\" content=\"In Android development, the SMS verification code feature can be implemented by following these steps: Add permission: Add the following permissions in the AndroidManifest.xml file. &lt;uses-permission android:name=&quot;android.permission.RECEIVE_SMS&quot;\/&gt; &lt;uses-permission android:name=&quot;android.permission.READ_SMS&quot;\/&gt; Create a BroadcastReceiver: Create a class that extends BroadcastReceiver to receive SMS verification codes. Override the onReceive() method in the class, which will be triggered when [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-16T09:32:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-22T12:19:27+00:00\" \/>\n<meta name=\"author\" content=\"Isabella Edwards\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Isabella Edwards\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/\"},\"author\":{\"name\":\"Isabella Edwards\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\"},\"headline\":\"Implementing SMS verification code function in Android development.\",\"datePublished\":\"2024-03-16T09:32:08+00:00\",\"dateModified\":\"2024-03-22T12:19:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/\"},\"wordCount\":151,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/\",\"name\":\"Implementing SMS verification code function in Android development. - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-16T09:32:08+00:00\",\"dateModified\":\"2024-03-22T12:19:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Implementing SMS verification code function in Android development.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\",\"name\":\"Isabella Edwards\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"caption\":\"Isabella Edwards\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Implementing SMS verification code function in Android development. - Blog - Silicon Cloud","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:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/","og_locale":"en_US","og_type":"article","og_title":"Implementing SMS verification code function in Android development.","og_description":"In Android development, the SMS verification code feature can be implemented by following these steps: Add permission: Add the following permissions in the AndroidManifest.xml file. &lt;uses-permission android:name=\"android.permission.RECEIVE_SMS\"\/&gt; &lt;uses-permission android:name=\"android.permission.READ_SMS\"\/&gt; Create a BroadcastReceiver: Create a class that extends BroadcastReceiver to receive SMS verification codes. Override the onReceive() method in the class, which will be triggered when [&hellip;]","og_url":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-16T09:32:08+00:00","article_modified_time":"2024-03-22T12:19:27+00:00","author":"Isabella Edwards","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Isabella Edwards","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/"},"author":{"name":"Isabella Edwards","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd"},"headline":"Implementing SMS verification code function in Android development.","datePublished":"2024-03-16T09:32:08+00:00","dateModified":"2024-03-22T12:19:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/"},"wordCount":151,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/","url":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/","name":"Implementing SMS verification code function in Android development. - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-16T09:32:08+00:00","dateModified":"2024-03-22T12:19:27+00:00","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/implementing-sms-verification-code-function-in-android-development\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Implementing SMS verification code function in Android development."}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd","name":"Isabella Edwards","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","caption":"Isabella Edwards"},"url":"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/27971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=27971"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/27971\/revisions"}],"predecessor-version":[{"id":62239,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/27971\/revisions\/62239"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=27971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=27971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=27971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}