Skip to content
Oxtro

Blog

Build your own Android SMS gateway in 10 steps

An Android phone with a SIM card can send and receive text messages for your applications, with no SMS provider in between. This guide walks through the setup with an open-source gateway app, the limits you will hit, and when a gateway on a phone is the wrong tool.

Last updated

Why build an Android SMS gateway?

An Android SMS gateway is an app on a phone that receives requests from your software and sends them as ordinary text messages from the phone's SIM card. Incoming messages go the other way, to your server.

It makes sense when:

  • you send a modest number of messages, such as alerts, reminders or codes for a small app;
  • your mobile plan includes unlimited or cheap local SMS, which can cost less than a provider for local traffic;
  • you want messages to come from a normal local number that people recognise and can reply to;
  • you need SMS in a country where business SMS providers are expensive or hard to sign up with;
  • you are prototyping and do not want a provider account yet.

It is the wrong tool for high volume, for critical messages that must always arrive, or for marketing to large lists. The limits section explains why.

Core concepts

  • Gateway app: runs on the phone, holds the permission to send SMS, and exposes an API.
  • Local mode: the app runs a small HTTP server on the phone, reachable from your local network.
  • Cloud mode: the phone keeps a connection to a relay server, so your application can reach it from anywhere without opening ports. You can use a hosted relay or run your own.
  • Webhooks: the app calls a URL on your server when a message arrives or its status changes.
  • Delivery reports: the carrier tells the phone whether each message was delivered, and the app passes that on.

This guide uses SMS Gateway for Android, an open-source app under the Apache 2.0 licence that supports local and cloud modes, webhooks and a self-hosted server. Other apps follow the same ideas.

Step-by-step setup guide

1. Choose a phone and a SIM plan

Any reasonably recent Android phone works. A dedicated phone is better than your personal one, so a full inbox or a forgotten silent mode never breaks your gateway. Choose a plan with enough SMS for your volume, and read its terms: some carriers forbid automated or commercial sending on consumer plans and may block the SIM.

2. Install the gateway app

Install the app from its official source, following the project's documentation. Apps that send SMS in the background are restricted on Google Play, which only allows SMS permissions for apps that act as the phone's default SMS app, so gateway apps are often installed directly from their release page.

3. Grant permissions and disable battery optimisation

Allow the app to send and receive SMS. Then exclude it from battery optimisation in Android's settings, otherwise the system will pause it when the screen is off and messages will wait until someone picks up the phone. Some manufacturers add their own background restrictions, so check those too.

4. Choose local or cloud mode

Use local mode if your application runs on the same network as the phone. Use cloud mode if your application runs on a server elsewhere. For sensitive messages, run your own relay server so message content does not pass through a third party.

5. Secure the API

The gateway can send messages that you pay for from a number tied to your identity, so treat it like any other credential:

  • keep the API credentials secret, on your server only;
  • never expose local mode directly to the internet;
  • use HTTPS between your application and the relay;
  • allow only your server's IP address where you can.

6. Send your first message

Send a test message to your own phone with the API call from the app's documentation. Check that it arrives, then check that your application records the message ID the gateway returns, so you can match status updates to it later.

7. Receive messages with webhooks

Register a webhook URL so the gateway posts incoming messages to your server. Respond quickly with a success status, and do the real work in the background, because the phone may retry if your server is slow.

8. Track delivery reports

Subscribe to status updates as well. A message that is sent but never delivered usually means the number is wrong, the phone was off, or the carrier filtered it. Log the final status of every message.

9. Raise Android's sending limit

Android asks the user to confirm before an app sends more than a set number of SMS in a short time, commonly 30 messages within a time window that varies by Android version. A gateway that hits this limit stops until someone taps the confirmation. You can raise the limit over ADB, without root:

bash
adb shell settings put global sms_outgoing_check_max_count 1000
adb shell settings put global sms_outgoing_check_interval_ms 60000

This allows up to 1,000 messages per minute as far as Android is concerned. Your carrier will have its own limits, and sending fast is the quickest way to get a SIM blocked, so pace messages in your application anyway.

10. Keep it running

  • Keep the phone on a charger, in a place with a good signal, with automatic updates postponed to a time you control.
  • Turn off anything that could interrupt it: screen lock apps, aggressive cleaners, do-not-disturb rules that affect apps.
  • Monitor it. Have your application alert you if no status updates arrive for a while, or if failures rise.
  • Keep a second phone or a provider account ready for when the first one fails.

Advanced configuration & troubleshooting

Multiple SIMs and phones

Dual-SIM phones can spread messages across two numbers, and several phones can share the load behind one server. Assign each recipient to the same SIM every time, so replies come back to the number they know.

Common issues and fixes

ProblemLikely causeFix
Messages queue but do not sendThe app was paused in the backgroundDisable battery optimisation and manufacturer restrictions
Sending stops after a few dozen messagesAndroid's SMS limitRaise the limit with ADB, see step 9
Sent but not deliveredWrong number format, phone off, or carrier filteringUse E.164 numbers, check the delivery report, slow down
SIM suddenly blockedThe carrier detected automated sendingLower volume, check your plan's terms, contact the carrier
Webhooks arrive twiceYour server responded slowly and the app retriedRespond fast, and deduplicate on the message ID
Long messages arrive in pieces or cost moreMessages over 160 characters, or 70 with emojis, are splitKeep messages short and avoid emojis in SMS

Limits of a phone as a gateway

  • Volume. A phone and a consumer SIM are not built for thousands of messages an hour. Carriers notice and may block the SIM.
  • Rules. In some countries business SMS must use registered senders and templates, which a personal SIM bypasses at the cost of being filtered or blocked.
  • Reliability. One phone is a single point of failure: a dead battery, a lost signal or an update stops everything.
  • Sender identity. Messages come from a plain phone number, not your brand name.

When you outgrow it, move to an SMS provider. For verification codes in particular, read the top 5 SMS verification providers.

The same idea on WhatsApp

If your customers read WhatsApp more than SMS, the same approach works there: link a number you own and send from your own code. That is what Oxtro, our product, does. You scan a QR code instead of installing an app on a dedicated phone, and you get a REST API, webhooks, a shared inbox and an OTP API. Oxtro is not the official WhatsApp Business Platform, and the same care about volume and consent applies. Start with the quickstart.

Connect your first number today

Create a workspace, scan the QR code and send a message.

Create account