{"id":19660,"date":"2026-11-19T01:28:20","date_gmt":"2026-11-18T19:58:20","guid":{"rendered":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/"},"modified":"2026-11-19T02:04:23","modified_gmt":"2026-11-18T20:34:23","slug":"otp-widget-android-kotlin-fast2sms","status":"publish","type":"post","link":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/","title":{"rendered":"Android OTP login screen in Kotlin (Jetpack Compose) with Fast2SMS Smart OTP"},"content":{"rendered":"<p>This Android example gives you a ready OTP login screen in Kotlin and Jetpack Compose. The user types a mobile number, gets a code by SMS or WhatsApp through Fast2SMS <strong>Smart OTP<\/strong>, types it or taps the code the keyboard suggests, and your app gets a signed &#8220;verified&#8221; token. The app talks only to your own backend, which holds the <a href=\"\/help\/api-key-find-reset\/\">API key<\/a>.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Add OTP login to your Android app<\/strong><p>Create a Smart OTP template and verify users by SMS or WhatsApp from your backend.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<p class=\"f2s-kit-wrap\"><a class=\"f2s-kit\" href=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/fast2sms-otp-widget-android-kotlin.zip\" download><svg class=\"f2s-kit__icon\" width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#7F56D9\" d=\"M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z\"\/><path fill=\"#FFFFFF\" d=\"M14 2v6h6\"\/><path fill=\"#FFFFFF\" d=\"M9 6h2v2H9zm2 2h2v2h-2zM9 10h2v2H9zm2 2h2v2h-2zm-2 2h4v4H9z\"\/><rect x=\"10\" y=\"15.4\" width=\"2\" height=\"1.6\" fill=\"#7F56D9\"\/><\/svg><span class=\"f2s-kit__text\"><strong>Download the Android (Kotlin) OTP widget example (zip)<\/strong><span class=\"f2s-kit__meta\">fast2sms-otp-widget-android-kotlin.zip &middot; 15 KB<\/span><\/span><span class=\"f2s-kit__btn\">Download .zip<\/span><\/a><\/p>\n<p class=\"f2s-kit-wrap\"><a class=\"f2s-kit\" href=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/fast2sms-otp-widget-all.zip\" download><svg class=\"f2s-kit__icon\" width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#7F56D9\" d=\"M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z\"\/><path fill=\"#FFFFFF\" d=\"M14 2v6h6\"\/><path fill=\"#FFFFFF\" d=\"M9 6h2v2H9zm2 2h2v2h-2zM9 10h2v2H9zm2 2h2v2h-2zm-2 2h4v4H9z\"\/><rect x=\"10\" y=\"15.4\" width=\"2\" height=\"1.6\" fill=\"#7F56D9\"\/><\/svg><span class=\"f2s-kit__text\"><strong>Download the complete OTP widget kit (zip)<\/strong><span class=\"f2s-kit__meta\">fast2sms-otp-widget-all.zip &middot; 1 MB<\/span><\/span><span class=\"f2s-kit__btn\">Download .zip<\/span><\/a><\/p>\n<div class=\"f2s-note f2s-note--warn\"><strong>Never put the Fast2SMS API key in the app:<\/strong> not in <code>BuildConfig<\/code>, <code>strings.xml<\/code>, <code>local.properties<\/code> or anywhere in the APK. APKs are easy to unpack. The key lives only in the backend&#8217;s environment, and the app only knows your backend URL.<\/div>\n<h2>What is in the Android example<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>File<\/th>\n<th>What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>F2sOtpClient.kt<\/code><\/td>\n<td><code>send<\/code>, <code>verify<\/code> and <code>resend<\/code> as suspend functions (<code>HttpURLConnection<\/code> and <code>org.json<\/code>), plus <code>cleanMobile<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>OtpScreen.kt<\/code><\/td>\n<td>The Compose screen: phone field with +91, Send, code field (<code>KeyboardType.NumberPassword<\/code> with the <code>ContentType.SmsOtpCode<\/code> autofill hint), resend countdown, errors and <code>onVerified(token, mobile)<\/code>. It ends with an optional SMS User Consent snippet.<\/td>\n<\/tr>\n<tr>\n<td><code>MainActivity.kt<\/code><\/td>\n<td>Shows the screen and where to send the token.<\/td>\n<\/tr>\n<tr>\n<td><code>AndroidManifest.xml<\/code>, <code>network_security_config.xml<\/code><\/td>\n<td>Internet permission and a local-only cleartext rule.<\/td>\n<\/tr>\n<tr>\n<td><code>app\/build.gradle.kts<\/code><\/td>\n<td>compileSdk 35, minSdk 24, Compose BOM, Material 3, coroutines.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>The app needs one of the kit&#8217;s backends to talk to (see the OTP widget overview).<\/p>\n<h2>Before you start<\/h2>\n<ul>\n<li>A Fast2SMS account with wallet balance.<\/li>\n<li>An approved DLT OTP template, or a WhatsApp Authentication or Utility template.<\/li>\n<li>Android Studio and a server for one of the backends.<\/li>\n<\/ul>\n<h2>Set up OTP on Android<\/h2>\n<ol class=\"f2s-steps\">\n<li>\n<h3>Create a Smart OTP template and copy its OTP ID<\/h3>\n<p>In the Fast2SMS panel, open <strong>Smart OTP<\/strong> &gt; <strong>OTP Template List<\/strong> and click <strong>Add OTP Template<\/strong>. Pick <strong>SMS Channel<\/strong> with your approved DLT OTP template, or <strong>WhatsApp Channel<\/strong> with an approved Authentication or Utility template. You can add a fallback on the other channel. Then copy the 10-character <strong>OTP ID<\/strong> from the card. It decides the channel, the template and the fallback for every code the widget sends.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-29-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Smart OTP Template page with WhatsApp and SMS OTP template cards, each showing its OTP ID, sender or number, template ID and fallback\"><figcaption>Copy the OTP ID from the template card.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Run a backend that holds your API key<\/h3>\n<p>The widget never calls Fast2SMS. It calls a small backend that you run, and only that backend knows your API key. The full kit has ready backends for PHP hosting (one file), Node.js with Express, Python Flask, Django, Laravel, Cloudflare Workers, Vercel or Netlify functions and Google Apps Script (see the OTP widget overview). Copy the key from <strong>API Key<\/strong> under UTILITY in the panel, and give the backend these three settings:<\/p>\n<pre><code class=\"language-bash\">FAST2SMS_API_KEY=YOUR_API_KEY\nF2S_OTP_ID=YOUR_OTP_ID\nF2S_TOKEN_SECRET=at-least-32-random-characters<\/code><\/pre>\n<p><code>F2S_TOKEN_SECRET<\/code> is any random text of 32 or more characters. The backend will not start (or, on PHP and serverless hosts, refuses every request) if one of these is missing or wrong. The app talks to this backend over HTTPS; use a URL such as <code>https:\/\/www.example.com\/f2s-otp<\/code>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-31-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"API Key page with the masked Authorization Key, View and Reset buttons and the API Access switch turned on\"><figcaption>The key goes into your backend settings only.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Add the files and set the endpoint<\/h3>\n<p>The example has no Gradle wrapper or root <code>settings.gradle.kts<\/code>. Create a new <strong>Empty Activity<\/strong> (Compose) project in Android Studio and copy in the files from <code>app\/src\/main\/java\/com\/example\/f2sotp\/<\/code>, or add them to your own app. In <code>MainActivity.kt<\/code>, set <code>OTP_ENDPOINT<\/code> to your backend URL and run.<\/p>\n<p>To test on the emulator with a backend on your computer, use <code>http:\/\/10.0.2.2:3000\/f2s-otp<\/code>. The included <code>res\/xml\/network_security_config.xml<\/code> allows plain <code>http<\/code> only to <code>10.0.2.2<\/code>. Remove it for release builds.<\/p>\n<\/li>\n<\/ol>\n<h2>Use the screen in your own app<\/h2>\n<pre><code class=\"language-kotlin\">const val OTP_ENDPOINT = \"https:\/\/www.example.com\/f2s-otp\" \/\/ your backend, never fast2sms.com\n\nclass MainActivity : ComponentActivity() {\n    private val client = F2sOtpClient(OTP_ENDPOINT)\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContent {\n            MaterialTheme {\n                OtpScreen(client) { token, _ -&gt;\n                    \/\/ Send the token to YOUR login API (field name e.g. f2s_token).\n                    \/\/ Your server checks it, then starts the session.\n                }\n            }\n        }\n    }\n}<\/code><\/pre>\n<p>For a second OTP ID, create the client as <code>F2sOtpClient(OTP_ENDPOINT, \"YOUR_OTP_ID\")<\/code>. The backend accepts it only if it is in <code>F2S_OTP_IDS<\/code>.<\/p>\n<h2>Reading the code from the SMS<\/h2>\n<ul>\n<li><code>ContentType.SmsOtpCode<\/code> lets the keyboard or autofill service offer the code. It needs Compose UI 1.8 or newer; on older Compose, remove that line and the keyboard&#8217;s own suggestion still works on most phones.<\/li>\n<li>For one-tap reading, use the optional SMS User Consent API snippet at the end of <code>OtpScreen.kt<\/code>. It needs <code>play-services-auth-api-phone<\/code> and reads the code after the user taps Allow.<\/li>\n<li>Codes sent on WhatsApp are not read from SMS; the user types or copies them.<\/li>\n<\/ul>\n<h2>What the app sends to your backend<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Request body<\/th>\n<th>Success answer<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>{\"action\":\"send\",\"mobile\":\"9999999999\"}<\/code><\/td>\n<td><code>ok<\/code>, <code>masked<\/code>, <code>resend_after<\/code>, <code>length<\/code>, <code>expires_in<\/code>, <code>ticket<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>{\"action\":\"verify\",\"mobile\":\"9999999999\",\"otp\":\"123456\",\"ticket\":\"...\"}<\/code><\/td>\n<td><code>ok<\/code>, <code>masked<\/code>, <code>token<\/code>, <code>expires_in<\/code> (600)<\/td>\n<\/tr>\n<tr>\n<td><code>{\"action\":\"resend\",\"mobile\":\"9999999999\",\"ticket\":\"...\"}<\/code><\/td>\n<td>same as send<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Every call is a <code>POST<\/code> to your endpoint with the headers <code>Content-Type: application\/json<\/code> and <code>X-F2S-Widget: 1<\/code>. Errors come back as <code>{\"ok\":false,\"reason\":\"...\",\"message\":\"...\"}<\/code>, and the screen shows <code>message<\/code>, which is plain English. The ticket from <code>send<\/code> is kept in memory only; <code>verify<\/code> and <code>resend<\/code> need it.<\/p>\n<h2>Check the token on your server<\/h2>\n<p>The <code>onVerified<\/code> callback in the app proves nothing to your server on its own. Send the token to your own log-in or sign-up API, check it there with the backend kit&#8217;s helper, and only then create the session:<\/p>\n<pre><code class=\"language-js\">\/\/ Node.js \/ Express backend kit\nconst v = await otp.verifyToken(req.body.f2s_token, { mobile: req.body.phone });\nif (&#33;v) return res.status(403).send('Mobile number not verified.');\n\/\/ v.mobile is the verified 10-digit number. A token works only once.<\/code><\/pre>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ PHP single-file backend kit\nrequire __DIR__ . '\/f2s-otp.php';\n$v = \\F2sOtp\\verify_token($_POST['f2s_token'] ?? '', $_POST['phone'] ?? null);\nif ($v === null) { http_response_code(403); exit('Mobile number not verified.'); }\n\/\/ $v['mobile'] is the verified 10-digit number.<\/code><\/pre>\n<p>The token lasts 10 minutes by default and works once. Use the number the helper returns, not a number the app sends separately.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Verify Android users with OTP<\/strong><p>Sign up for Fast2SMS, copy your OTP ID and keep the key on your server.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>How the backend protects an app<\/h2>\n<p>A browser sends an <code>Origin<\/code> header, and the backend uses it to block other websites. Mobile apps send no <code>Origin<\/code> header, so that check does not apply to them. What protects your wallet against app requests is:<\/p>\n<ul>\n<li>the resend wait (30 seconds by default),<\/li>\n<li>the per-number and per-IP limits (5 and 20 sends per hour by default),<\/li>\n<li>the limit on wrong codes (5 by default),<\/li>\n<li>an optional captcha (Cloudflare Turnstile or reCAPTCHA, off by default).<\/li>\n<\/ul>\n<p>The example screen does not include a captcha. If you turn <code>F2S_CAPTCHA<\/code> on, your app must send a captcha token in the <code>captcha<\/code> field of the <code>send<\/code> call. For high volume, also check a Google Play Integrity token on the backend before it sends a code, so only your real app can ask for codes.<\/p>\n<p>Do not set an <code>Origin<\/code> header in the app. If you do and it is not in the backend&#8217;s allowed list, the backend answers &#8220;This page is not allowed to use this OTP service.&#8221;<\/p>\n<h2>Limits and cost<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Backend setting<\/th>\n<th>Default<\/th>\n<th>What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>F2S_RESEND_WAIT<\/code><\/td>\n<td>30 seconds<\/td>\n<td>Wait between two sends to one number.<\/td>\n<\/tr>\n<tr>\n<td><code>F2S_LIMIT_PER_NUMBER<\/code><\/td>\n<td>5 per hour<\/td>\n<td>Sends to one mobile number.<\/td>\n<\/tr>\n<tr>\n<td><code>F2S_LIMIT_PER_IP<\/code><\/td>\n<td>20 per hour<\/td>\n<td>Sends from one IP address.<\/td>\n<\/tr>\n<tr>\n<td><code>F2S_LIMIT_VERIFY_PER_IP<\/code><\/td>\n<td>60 per hour<\/td>\n<td>Verify calls from one IP address.<\/td>\n<\/tr>\n<tr>\n<td><code>F2S_MAX_VERIFY<\/code><\/td>\n<td>5<\/td>\n<td>Wrong codes allowed for one code.<\/td>\n<\/tr>\n<tr>\n<td><code>F2S_TOKEN_TTL<\/code><\/td>\n<td>600 seconds<\/td>\n<td>How long the verified token lasts.<\/td>\n<\/tr>\n<tr>\n<td><code>F2S_CAPTCHA<\/code><\/td>\n<td>off<\/td>\n<td><code>turnstile<\/code> or <code>recaptcha<\/code>, with <code>F2S_CAPTCHA_SECRET<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Fast2SMS also has its own limits in <strong>Smart OTP<\/strong> &gt; <strong>OTP Settings<\/strong>: <strong>Max Verify OTP Limit (Per SMS)<\/strong> and <strong>SMS Resend \/ Time Limit (Seconds)<\/strong>. The backend&#8217;s own limits apply first.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-settings-hd-22-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"OTP Settings page with Max Verify OTP Limit set to 5 and SMS Resend \/ Time Limit set to 30 seconds\"><figcaption>Fast2SMS has its own attempt and resend limits too.<\/figcaption><\/figure>\n<p><strong>Resend sends the same code again.<\/strong> Fast2SMS allows it within 10 minutes of the first send, up to 5 sends in total. Sending a fresh code for a number cancels the older code. If the template has a fallback and the first channel fails, Fast2SMS sends the same code once on the other channel.<\/p>\n<p>Each send and each resend is charged at your Smart OTP rate. Verify is free. If a fallback message goes out on the second channel, that message is charged too, and so is a <strong>Test OTP<\/strong> from the template card, because it is a real send. See the current rates on the <a href=\"https:\/\/www.fast2sms.com\/otp-sms\">Smart OTP page<\/a>.<\/p>\n<div class=\"f2s-note f2s-volume\"><p><strong>Sending in bulk?<\/strong> For high OTP volumes our team offers discounted rates. <a href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Talk to our team<\/a> or see <a href=\"https:\/\/www.fast2sms.com\/bulk-sms-pricing\">OTP pricing<\/a>.<\/p><\/div>\n<h2>Test status<\/h2>\n<div class=\"f2s-note\">This Android example has <strong>not been run yet<\/strong>. There was no Android SDK, Gradle or Kotlin compiler on the test machine, so the code was reviewed only. Build it in Android Studio, test it on a real phone and do one live send before you release.<\/div>\n<h2>Common problems and fixes<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>What you see<\/th>\n<th>Why<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&#8220;Could not reach the server&#8230;&#8221;<\/td>\n<td>Wrong endpoint, backend not running, or cleartext blocked.<\/td>\n<td>Check <code>OTP_ENDPOINT<\/code>. On the emulator use <code>10.0.2.2<\/code>, not <code>localhost<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>Unresolved reference: SmsOtpCode<\/code><\/td>\n<td>Compose UI older than 1.8.<\/td>\n<td>Update the Compose BOM, or remove the <code>contentType<\/code> line.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;We could not send the code right now&#8230;&#8221;<\/td>\n<td>A backend setup problem: wrong OTP ID, low balance, key refused.<\/td>\n<td>Read the backend log. It names the real reason.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Please wait N seconds&#8230;&#8221;<\/td>\n<td>The resend wait.<\/td>\n<td>Wait for the countdown.<\/td>\n<\/tr>\n<tr>\n<td>Code sent but nothing arrives<\/td>\n<td>Sent means Fast2SMS accepted it, not that the phone got it.<\/td>\n<td>Check <strong>Smart OTP<\/strong> &gt; <strong>Delivery Report<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>The code is not suggested<\/td>\n<td>It depends on the phone and keyboard.<\/td>\n<td>The user can type it, or add the SMS User Consent snippet.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<section class=\"f2s-faq\">\n<h2>Frequently asked questions<\/h2>\n<h3>Can I put my Fast2SMS API key in BuildConfig?<\/h3>\n<p>No. Anything in the APK, including <code>BuildConfig<\/code> and <code>strings.xml<\/code>, can be extracted. Keep the key on the backend and let the app call your endpoint.<\/p>\n<h3>Do I need the SMS Retriever API?<\/h3>\n<p>No. The screen already offers the code through the keyboard. The optional SMS User Consent snippet reads it after one tap. Fully automatic SMS Retriever reading needs an app hash in the SMS text, which your DLT template would have to allow.<\/p>\n<h3>What is the minimum Android version?<\/h3>\n<p>The example&#8217;s <code>build.gradle.kts<\/code> sets minSdk 24 and compileSdk 35.<\/p>\n<h3>Does this work with XML layouts instead of Compose?<\/h3>\n<p>The screen is written in Compose. <code>F2sOtpClient.kt<\/code> has no UI code, so you can call it from a Views-based screen yourself.<\/p>\n<h3>Can the OTP go on WhatsApp instead of SMS?<\/h3>\n<p>Yes. The OTP ID on the backend picks the channel. Use a WhatsApp OTP template, or an SMS template with a WhatsApp fallback.<\/p>\n<h3>Does Resend send a new code?<\/h3>\n<p>No. Resend sends the same code again, within 10 minutes and up to 5 sends in total. Each resend is charged.<\/p>\n<\/section>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Launch OTP login on Android<\/strong><p>Create your Fast2SMS account and verify mobile numbers by SMS or WhatsApp.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Related guides<\/h2>\n<ul>\n<li><a href=\"\/help\/android-otp-sms-api\/\">OTP verification in an Android app (Kotlin) with Fast2SMS: the safe way<\/a><\/li>\n<li><a href=\"\/help\/otp-autofill-android-ios-sms-retriever\/\">OTP autofill on Android, iPhone and websites: SMS Retriever, app hash and DLT<\/a><\/li>\n<li><a href=\"\/help\/otp-website-login-vs-app-login\/\">OTP for website login vs app login: what changes and what stays the same<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-setup-guide-fast2sms\/\">Smart OTP in Fast2SMS: set up OTP on SMS and WhatsApp with fallback<\/a><\/li>\n<li><a href=\"\/help\/otp-sms-pumping-fraud-protection\/\">OTP fraud and SMS pumping: how to protect your OTP form and wallet<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This Android example gives you a ready OTP login screen in Kotlin and Jetpack Compose. The user types a mobile number, gets a code by SMS or WhatsApp through Fast2SMS Smart OTP, types it or taps the code the keyboard suggests, and your app gets a signed &#8220;verified&#8221; token. The app talks only to your [&hellip;]<\/p>\n","protected":false},"featured_media":19641,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[],"class_list":["post-19660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-otp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android Kotlin OTP Login Screen (Compose) | Fast2SMS<\/title>\n<meta name=\"description\" content=\"A ready Android OTP login screen in Kotlin and Jetpack Compose for Fast2SMS Smart OTP: SMS or WhatsApp codes, autofill and a server-side token check.\" \/>\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.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Kotlin OTP Login Screen (Compose) | Fast2SMS\" \/>\n<meta property=\"og:description\" content=\"A ready Android OTP login screen in Kotlin and Jetpack Compose for Fast2SMS Smart OTP: SMS or WhatsApp codes, autofill and a server-side token check.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/\" \/>\n<meta property=\"og:site_name\" content=\"Fast2SMS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Fast2SMS\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T19:58:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T20:34:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-29-scaled.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fast2sms\" \/>\n<meta name=\"twitter:site\" content=\"@fast2sms\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"headline\":\"Android OTP login screen in Kotlin (Jetpack Compose) with Fast2SMS Smart OTP\",\"datePublished\":\"2026-11-18T19:58:20+00:00\",\"dateModified\":\"2026-11-18T20:34:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/\"},\"wordCount\":1630,\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-29-scaled.webp\",\"articleSection\":[\"API\",\"OTP\"],\"inLanguage\":\"en-IN\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/\",\"name\":\"Android Kotlin OTP Login Screen (Compose) | Fast2SMS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-29-scaled.webp\",\"datePublished\":\"2026-11-18T19:58:20+00:00\",\"dateModified\":\"2026-11-18T20:34:23+00:00\",\"description\":\"A ready Android OTP login screen in Kotlin and Jetpack Compose for Fast2SMS Smart OTP: SMS or WhatsApp codes, autofill and a server-side token check.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/#breadcrumb\"},\"inLanguage\":\"en-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-IN\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-29-scaled.webp\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-template-list-hd-29-scaled.webp\",\"width\":2560,\"height\":1600,\"caption\":\"Smart OTP Template page with WhatsApp and SMS OTP template cards, each showing its OTP ID, sender or number, template ID and fallback\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-widget-android-kotlin-fast2sms\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/api\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Android OTP login screen in Kotlin (Jetpack Compose) with Fast2SMS Smart OTP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\",\"name\":\"Fast2SMS\",\"description\":\"Help\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"inLanguage\":\"en-IN\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\",\"name\":\"Fast2SMS\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"caption\":\"Fast2SMS\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\"},\"email\":\"support@fast2sms.com\",\"telephone\":\"+91-6262778822\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Fast2SMS\",\"https:\\\/\\\/www.instagram.com\\\/fast2sms\",\"https:\\\/\\\/x.com\\\/fast2sms\",\"https:\\\/\\\/www.youtube.com\\\/Fast2SMSofficial\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/fast2sms\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Kotlin OTP Login Screen (Compose) | Fast2SMS","description":"A ready Android OTP login screen in Kotlin and Jetpack Compose for Fast2SMS Smart OTP: SMS or WhatsApp codes, autofill and a server-side token check.","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.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/","og_locale":"en_US","og_type":"article","og_title":"Android Kotlin OTP Login Screen (Compose) | Fast2SMS","og_description":"A ready Android OTP login screen in Kotlin and Jetpack Compose for Fast2SMS Smart OTP: SMS or WhatsApp codes, autofill and a server-side token check.","og_url":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/","og_site_name":"Fast2SMS","article_publisher":"https:\/\/www.facebook.com\/Fast2SMS\/","article_published_time":"2026-11-18T19:58:20+00:00","article_modified_time":"2026-11-18T20:34:23+00:00","og_image":[{"width":2560,"height":1600,"url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-29-scaled.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_creator":"@fast2sms","twitter_site":"@fast2sms","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/#article","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/"},"author":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"headline":"Android OTP login screen in Kotlin (Jetpack Compose) with Fast2SMS Smart OTP","datePublished":"2026-11-18T19:58:20+00:00","dateModified":"2026-11-18T20:34:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/"},"wordCount":1630,"publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-29-scaled.webp","articleSection":["API","OTP"],"inLanguage":"en-IN"},{"@type":"WebPage","@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/","url":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/","name":"Android Kotlin OTP Login Screen (Compose) | Fast2SMS","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/#primaryimage"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-29-scaled.webp","datePublished":"2026-11-18T19:58:20+00:00","dateModified":"2026-11-18T20:34:23+00:00","description":"A ready Android OTP login screen in Kotlin and Jetpack Compose for Fast2SMS Smart OTP: SMS or WhatsApp codes, autofill and a server-side token check.","breadcrumb":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/#breadcrumb"},"inLanguage":"en-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/"]}]},{"@type":"ImageObject","inLanguage":"en-IN","@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/#primaryimage","url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-29-scaled.webp","contentUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-29-scaled.webp","width":2560,"height":1600,"caption":"Smart OTP Template page with WhatsApp and SMS OTP template cards, each showing its OTP ID, sender or number, template ID and fallback"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fast2sms.com\/help\/otp-widget-android-kotlin-fast2sms\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fast2sms.com\/help\/"},{"@type":"ListItem","position":2,"name":"API","item":"https:\/\/www.fast2sms.com\/help\/api\/"},{"@type":"ListItem","position":3,"name":"Android OTP login screen in Kotlin (Jetpack Compose) with Fast2SMS Smart OTP"}]},{"@type":"WebSite","@id":"https:\/\/www.fast2sms.com\/help\/#website","url":"https:\/\/www.fast2sms.com\/help\/","name":"Fast2SMS","description":"Help","publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"inLanguage":"en-IN"},{"@type":"Organization","@id":"https:\/\/www.fast2sms.com\/#organization","name":"Fast2SMS","url":"https:\/\/www.fast2sms.com\/","logo":{"@type":"ImageObject","@id":"https:\/\/www.fast2sms.com\/#logo","url":"https:\/\/www.fast2sms.com\/Fast2SMS.png","contentUrl":"https:\/\/www.fast2sms.com\/Fast2SMS.png","caption":"Fast2SMS"},"image":{"@id":"https:\/\/www.fast2sms.com\/#logo"},"email":"support@fast2sms.com","telephone":"+91-6262778822","sameAs":["https:\/\/www.facebook.com\/Fast2SMS","https:\/\/www.instagram.com\/fast2sms","https:\/\/x.com\/fast2sms","https:\/\/www.youtube.com\/Fast2SMSofficial","https:\/\/www.linkedin.com\/company\/fast2sms"]}]}},"_links":{"self":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/19660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/comments?post=19660"}],"version-history":[{"count":1,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/19660\/revisions"}],"predecessor-version":[{"id":20032,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/19660\/revisions\/20032"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media\/19641"}],"wp:attachment":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media?parent=19660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/categories?post=19660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/tags?post=19660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}