Skip to main content

Prerequisites

Before you begin:

  • A SpringEdge account with an API key and your SMS service URL (<SMS_SERVICE_URL>, shared after sign-up)
  • A backend server (PHP, Node.js, etc.) that holds the API key and calls SpringEdge
  • Android Studio with minimum SDK 21 (Lollipop)
  • Internet permission in your AndroidManifest.xml
  • OkHttp dependency in your build.gradle

Gradle Dependency:

implementation 'com.squareup.okhttp3:okhttp:4.12.0'

No SMS Permission Needed

Uses HTTP API — no SEND_SMS permission required

Kotlin Coroutines

Non-blocking API calls with modern Kotlin async

Secure by Default

API key stays on your server; the app never sees it

// Kotlin with Coroutines — calls YOUR backend,
// never SpringEdge directly
import kotlinx.coroutines.*
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request

private val client = OkHttpClient()

// Your own server endpoint (holds the API key)
private const val BACKEND_URL =
    "https://your-backend.example.com/otp/send"

suspend fun requestOtp(
    phone: String
): String = withContext(Dispatchers.IO) {

    val body = FormBody.Builder()
        .add("phone", phone)
        .build()

    val request = Request.Builder()
        .url(BACKEND_URL)
        .post(body)
        // authenticate the app user with your
        // own session/token here if needed
        .build()

    client.newCall(request).execute().use {
        it.body?.string() ?: "No response"
    }
}

// Usage in Activity/ViewModel:
// lifecycleScope.launch {
//     val result = requestOtp("9900XXXXXX")
//     Log.d("SMS", result)
// }

KOTLIN

Using Kotlin Coroutines

The Android app must not contain your SpringEdge API key — anything shipped in an APK can be extracted and used to send SMS on your account. Instead, the app calls your own backend with Kotlin coroutines and OkHttp (on Dispatchers.IO, off the main thread), and your backend calls SpringEdge.

On the server, generate the OTP and send a form-encoded POST to <SMS_SERVICE_URL>/api/web/send/ (your SMS service URL, shared after sign-up) with the apikey parameter:

<?php
// your-backend: /otp/send
$phone = $_POST['phone'];
$otp = random_int(100000, 999999);
// store $otp against $phone for verification

$ch = curl_init('<SMS_SERVICE_URL>/api/web/send/');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => http_build_query([
        'apikey'  => getenv('SPRINGEDGE_API_KEY'),
        'sender'  => 'SEDEMO',
        'to'      => $phone,
        'message' => "Your OTP is $otp",
        'format'  => 'json',
    ]),
    CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
// {"groupID": 61, "MessageIDs": "61-1",
//  "status": "AWAITED-DLR"}
curl_close($ch);

Important:

  • Never put the SpringEdge API key in app code — always proxy through your backend server, and restrict the key to your server's whitelisted IPs
  • Add INTERNET permission to AndroidManifest.xml
  • Network calls must be off the main thread
  • See the SMS API documentation for all parameters and error messages

What You Can Build

OTP Verification

Add phone number verification to your Android app's registration and login flows with auto-read OTP support.

In-App Notifications

Send order updates, appointment reminders, and delivery alerts to users who have opted in to SMS notifications.

Two-Factor Auth

Implement SMS-based 2FA as a second authentication factor alongside biometric or password login.

Invite & Share

Let users invite friends via SMS with deep links that open directly in your app when clicked.