Skip to main content

Prerequisites

Before you begin:

  • A SpringEdge account with an API key
  • 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

HTTPS + Bearer token auth over TLS

// Kotlin with Coroutines
import kotlinx.coroutines.*
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

suspend fun sendSms(
    phone: String, message: String
): String = withContext(Dispatchers.IO) {

    val client = OkHttpClient()
    val json = """
    {
      "to": "$phone",
      "sender_id": "SPREDG",
      "message": "$message",
      "type": "transactional"
    }
    """.trimIndent()

    val body = json.toRequestBody(
        "application/json".toMediaType()
    )

    val request = Request.Builder()
        .url("https://api.springedge.com"
             + "/v1/sms/send")
        .post(body)
        .addHeader("Authorization",
            "Bearer YOUR_API_KEY")
        .build()

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

// Usage in Activity/ViewModel:
// lifecycleScope.launch {
//     val result = sendSms(
//         "+919876543210",
//         "Your OTP is 482910"
//     )
//     Log.d("SMS", result)
// }

KOTLIN

Using Kotlin Coroutines

This example uses Kotlin coroutines with OkHttp to send SMS from an Android app without blocking the main thread. The API call runs on Dispatchers.IO and returns the response as a string.

Call the function from any lifecycleScope or viewModelScope in your Activity, Fragment, or ViewModel.

Important:

  • Never store API keys in client-side code for production — proxy through your backend server
  • Add INTERNET permission to AndroidManifest.xml
  • Network calls must be off the main thread

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.