Mobile Dev

Create SMS/MMS Messenger App for Offline Group Chat

Learn how to build an SMS/MMS messenger app like iMessage for offline communication with group messaging. Use Android SmsManager API, cloud gateways like Twilio, self-hosted solutions, or mesh networks for reliable messaging without internet.

1 answer 1 view

How can I create a messenger application that operates via SMS and MMS for communication when internet is unavailable? The system should function similarly to iMessage with group messaging capabilities, allowing groups to send and receive messages through SMS and MMS without requiring an internet connection.

Creating an SMS/MMS-based messenger application requires understanding mobile development frameworks, SMS/MMS protocols, and offline communication architectures. By leveraging native Android SmsManager API or cloud-based SMS gateways, you can build a robust messaging system that operates without internet connectivity while supporting group messaging functionality similar to iMessage.


Contents


Understanding SMS/MMS Technology for Offline Messaging

SMS (Short Message Service) and MMS (Multimedia Messaging Service) are cellular network technologies that enable communication without internet connectivity. Unlike modern messaging apps that require internet access, SMS/MMS messages are transmitted through cellular carrier networks, making them ideal for offline communication scenarios. This fundamental difference makes SMS/MMS-based messaging solutions particularly valuable in areas with unreliable internet connectivity or during emergencies when network infrastructure might be compromised.

SMS messages are text-only, limited to 160 characters per message, while MMS supports multimedia content including images, videos, audio clips, and longer text messages. Both technologies utilize the cellular network infrastructure rather than internet protocols, ensuring reliable delivery in areas with poor or no internet coverage. When developing an SMS/MMS messenger application, you’ll need to consider the technical limitations and constraints of these protocols while leveraging their inherent offline capabilities.

Key Technical Considerations

When building an SMS/MMS-based messenger, several important technical factors must be addressed:

  • Carrier limitations: Different carriers impose varying restrictions on message size, frequency, and content type
  • Cost structure: SMS/MMS messages typically incur per-message charges from cellular carriers
  • Delivery confirmation: Implementing read receipts and message delivery status tracking
  • Security considerations: Messages are transmitted in plaintext unless additional encryption is implemented
  • Character encoding: Proper handling of Unicode characters for international messaging

Understanding these constraints will help you design a messaging application that works reliably across different network conditions and carrier environments.


Native Android Development Approach with SmsManager API

For native Android development, the SmsManager API provides the core functionality for sending and receiving SMS/MMS messages. This approach offers maximum control over the messaging functionality but requires careful implementation of various technical components. The Android developer documentation provides comprehensive technical details for implementing SMS functionality in Android applications.

Setting Up Permissions and Dependencies

To use SMS functionality in your Android application, you’ll need to declare the appropriate permissions in your AndroidManifest.xml:

xml
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />

These permissions allow your application to send, receive, and read SMS/MMS messages. Modern Android versions also require runtime permission handling for these sensitive permissions, so you’ll need to implement proper permission request flows at runtime.

Implementing Message Sending

The core SMS sending functionality can be implemented using SmsManager:

java
SmsManager smsManager = SmsManager.getDefault();
String phoneNumber = contactPhoneNumber;
String message = "Your message here";

// For messages longer than 160 characters, use divideMessage
String[] parts = smsManager.divideMessage(message);
PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0, 
 new Intent("SMS_SENT"), 0);

// Send the message
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, 
 sentIntents, null);

This code handles both short messages and longer messages that need to be split into multiple parts. The PendingIntent allows you to track the delivery status of the message through a BroadcastReceiver.

Receiving Messages

To receive SMS messages, you’ll need to implement a BroadcastReceiver:

java
public class SmsReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context context, Intent intent) {
 Bundle bundle = intent.getExtras();
 if (bundle != null) {
 Object[] pdus = (Object[]) bundle.get("pdus");
 if (pdus != null) {
 for (Object pdu : pdus) {
 SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdu);
 String messageBody = smsMessage.getMessageBody();
 String sender = smsMessage.getOriginatingAddress();
 
 // Process the received message
 processIncomingMessage(sender, messageBody);
 }
 }
 }
 }
}

This BroadcastReceiver will be triggered whenever an SMS message is received by the device. You’ll need to register it in your AndroidManifest.xml with appropriate intent filters.

Multi-SIM Support

Modern Android devices often have multiple SIM cards, and handling this properly requires additional consideration:

java
// Get SmsManager for specific subscription
SmsManager smsManager = SubscriptionManager.getDefaultSmsSubscriptionManager()
 .createSmsManagerForSubscriptionId(subscriptionId);

This allows you to specify which SIM card to use for sending messages, which is particularly important in regions where different carriers have different coverage or pricing structures.


Implementing Group Messaging with SMS/MMS

Group messaging functionality is a key requirement for an SMS/MMS-based messenger application similar to iMessage. While SMS/MMS protocols don’t inherently support group messaging in the same way that modern messaging apps do, you can implement this functionality through various approaches that leverage the underlying SMS/MMS infrastructure.

Native Group Messaging Implementation

One approach is to implement group messaging by sending the same message to multiple recipients individually. This can be achieved using the SmsManager API:

java
public void sendGroupMessage(List<String> phoneNumbers, String message) {
 SmsManager smsManager = SmsManager.getDefault();
 
 for (String phoneNumber : phoneNumbers) {
 String[] parts = smsManager.divideMessage(message);
 ArrayList<PendingIntent> sentIntents = new ArrayList<>();
 
 // Create PendingIntent for each message
 for (String part : parts) {
 sentIntents.add(PendingIntent.getBroadcast(context, 0, 
 new Intent("SMS_SENT"), 0));
 }
 
 // Send message to each recipient
 smsManager.sendMultipartTextMessage(phoneNumber, null, parts, 
 sentIntents, null);
 }
}

However, this approach has limitations, as each recipient will see their own individual message rather than a unified group conversation. To create a more iMessage-like experience, you’ll need additional mechanisms for message threading and conversation management.

Using Intent for Group Messaging

Android provides built-in support for group messaging through Intent actions. You can use the built-in messaging app’s capabilities to send group messages:

java
public void sendGroupMessageViaIntent(List<String> phoneNumbers, String message) {
 Intent intent = new Intent(Intent.ACTION_SENDTO);
 intent.setData(Uri.parse("smsto:" + TextUtils.join(",", phoneNumbers)));
 intent.putExtra("sms_body", message);
 startActivity(intent);
}

This approach leverages the system’s built-in group messaging functionality but gives you less control over the messaging experience and delivery tracking.

Threaded Messaging Implementation

For a more sophisticated group messaging experience, you’ll need to implement message threading and conversation management:

java
public class GroupMessageThread {
 private String groupId;
 private List<String> participants;
 private List<Message> messages;
 
 public void addMessage(Message message) {
 messages.add(message);
 // Notify all participants
 notifyParticipants(message);
 }
 
 private void notifyParticipants(Message message) {
 SmsManager smsManager = SmsManager.getDefault();
 String threadMessage = formatThreadMessage(message);
 
 for (String participant : participants) {
 String[] parts = smsManager.divideMessage(threadMessage);
 smsManager.sendMultipartTextMessage(participant, null, 
 parts, null, null);
 }
 }
 
 private String formatThreadMessage(Message message) {
 return String.format("[%s] %s: %s", groupId, 
 message.getSender(), message.getContent());
 }
}

This approach creates a more cohesive group messaging experience by adding context and threading to the messages, though it still relies on individual SMS/MMS delivery to each participant.

MMS for Multimedia Group Messages

For group messages containing multimedia content, you’ll need to implement MMS functionality:

java
public void sendGroupMMS(List<String> phoneNumbers, String text, Uri imageUri) {
 try {
 MultipartSmsSender sender = MultipartSmsSender.getInstance();
 PduComposer pduComposer = new PduComposer(context);
 
 // Create MMS message
 SendReq sendReq = pduComposer.makeSendReq(phoneNumbers, text, imageUri);
 
 // Send MMS
 sender.sendMultimediaMessage(sendReq);
 } catch (Exception e) {
 // Handle error
 }
}

This implementation allows you to send images, videos, and other multimedia content to group recipients through MMS messages.


Cloud-Based SMS Gateway Solutions

Cloud-based SMS gateways offer a robust alternative to native development for building SMS/MMS-based messenger applications. These services provide APIs that abstract away the complexities of dealing directly with cellular carriers and handling SMS/MMS protocols directly on device. Solutions like Twilio’s Conversations API provide comprehensive messaging platforms with global reach and built-in features for group messaging.

Advantages of Cloud-Based Solutions

Cloud-based SMS gateways offer several significant advantages for developers:

  • Global reach: These services have established relationships with carriers worldwide, ensuring reliable message delivery across different countries and networks
  • Scalability: Cloud solutions can handle message volumes that would be impractical to manage with native implementations
  • Feature-rich: Built-in support for message tracking, delivery confirmations, and advanced messaging features
  • Compliance: Many services handle regulatory compliance requirements automatically
  • Monitoring and analytics: Comprehensive dashboards for tracking message delivery, costs, and performance

Popular Cloud SMS Gateway Services

Several cloud-based SMS gateway services are particularly well-suited for building messenger applications:

Twilio: Offers a comprehensive Conversations API that supports both SMS and MMS messaging. Their platform provides tools for creating unified messaging experiences across different channels with features like message threading, delivery receipts, and media sharing.

MessageBird: Provides a robust messaging API with support for group messaging, message scheduling, and delivery analytics. Their platform includes features specifically designed for building chat applications.

Vonage (Nexmo): Offers a powerful messaging API with global coverage and features like message templates, delivery tracking, and webhook support for real-time message updates.

Implementation Example with Twilio

Here’s a basic implementation example using Twilio’s API for sending group SMS messages:

javascript
// Node.js example using Twilio SDK
const accountSid = 'your_account_sid';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

async function sendGroupSMS(phoneNumbers, message) {
 for (const number of phoneNumbers) {
 await client.messages.create({
 body: message,
 from: '+1234567890', // Your Twilio phone number
 to: number
 });
 }
}

// Usage
sendGroupSMS(['+1234567891', '+1234567892'], 'Hello group!');

This implementation sends the same message to multiple recipients, effectively creating a group messaging experience through individual SMS messages.

Cost Considerations

Cloud-based SMS gateways typically charge per message sent, with different pricing for SMS and MMS messages. Group messaging will incur charges for each recipient, making cost management an important consideration:

  • SMS pricing: Usually ranges from $0.005 to $0.05 per message depending on volume and destination
  • MMS pricing: Typically 2-3 times more expensive than SMS messages
  • International messaging: Additional charges may apply for messages sent to international numbers
  • Volume discounts: Most providers offer discounted rates for higher message volumes

Integration Challenges

When implementing cloud-based SMS gateways, several integration challenges should be considered:

  • Phone number management: You’ll need to acquire and manage virtual phone numbers through the gateway provider
  • Message delivery tracking: Implement proper webhook handlers to track message delivery status
  • Rate limiting: Handle API rate limits to avoid service interruptions
  • Error handling: Implement robust error handling for message failures and retries
  • Security: Secure your API keys and implement proper authentication mechanisms

Self-Hosted SMS Gateway Options

For developers seeking more control over their SMS/MMS infrastructure or looking to reduce ongoing costs, self-hosted SMS gateway solutions provide an attractive alternative to cloud-based services. These solutions allow you to run your own SMS gateway using hardware like GSM modems or repurposed Android devices, giving you complete control over your messaging infrastructure without relying on third-party providers.

Android Phone as SMS Gateway

One popular approach is to use an Android phone as an SMS gateway. The httpsms project demonstrates how to turn an Android phone into a full-fledged SMS gateway with an HTTP API, allowing you to send and receive SMS messages through standard web requests.

This approach offers several advantages:

  • Cost-effective: Uses existing hardware or inexpensive Android devices
  • Full control: Complete ownership of your messaging infrastructure
  • Privacy: Messages pass through your own servers rather than third-party platforms
  • Customization: Tailor the gateway to your specific application requirements

Here’s a basic implementation example using the httpsms API:

python
import requests

def send_sms(phone_number, message):
 api_url = "https://your-android-phone-ip:8080/api/v1/sms/send"
 headers = {
 "Content-Type": "application/json",
 "Authorization": "Bearer YOUR_API_TOKEN"
 }
 data = {
 "phone": phone_number,
 "message": message
 }
 
 response = requests.post(api_url, json=data, headers=headers)
 return response.json()

# Send group message
def send_group_sms(phone_numbers, message):
 results = []
 for number in phone_numbers:
 result = send_sms(number, message)
 results.append(result)
 return results

GSM Modem-Based Solutions

For higher volume requirements, GSM modems provide a more robust solution for self-hosted SMS gateways. The smsgate project is a Python-based server that uses GSM modems to send and receive SMS messages, offering a scalable self-hosted alternative.

Key features of GSM modem-based solutions:

  • High throughput: Can handle hundreds or thousands of messages per hour
  • Multiple modems: Scale by adding multiple GSM modems
  • Reliability: Industrial hardware designed for continuous operation
  • Cost-effective at scale: Lower per-message costs than cloud solutions for high volumes

Implementation Steps for Self-Hosted Gateway

Setting up a self-hosted SMS gateway typically involves these steps:

  1. Hardware acquisition: Obtain Android devices or GSM modems with appropriate connectivity
  2. Software installation: Install gateway software like httpsms or smsgate
  3. Network configuration: Ensure proper network access and port forwarding
  4. API development: Create endpoints for sending/receiving messages
  5. Security implementation: Set up authentication, encryption, and access controls
  6. Monitoring: Implement logging, monitoring, and alerting systems

Challenges and Limitations

Self-hosted SMS gateways present several challenges that must be addressed:

  • Hardware maintenance: Devices require physical maintenance, updates, and potential replacement
  • Network connectivity: Reliable internet connectivity is essential for gateway operation
  • Scalability: Scaling requires additional hardware and configuration
  • Carrier relationships: Without direct carrier relationships, message delivery may be less reliable
  • Regulatory compliance: You’re responsible for compliance with messaging regulations in your operating regions

Community and Open-Source Solutions

Several open-source projects and community resources can help with self-hosted SMS gateway implementation:

  • OpenBTS: Open-source software that turns a computer into a GSM base station
  • SMSTools: Linux-based SMS server for managing GSM modems
  • Kannel: Open-source WAP and SMS gateway
  • Gnokii: Linux tool suite for mobile phones

These projects provide the foundation for building custom SMS gateways tailored to your specific requirements.


Mesh Network Solutions for True Offline Communication

For scenarios where cellular connectivity is completely unavailable, mesh network solutions offer a revolutionary approach to offline messaging. Unlike traditional SMS/MMS-based messaging that requires cellular network infrastructure, mesh networks create direct communication channels between devices using technologies like Bluetooth, Wi-Fi Direct, or other wireless protocols. Solutions like Bridgefy demonstrate how these technologies can create truly offline messaging ecosystems.

How Mesh Networks Enable Offline Messaging

Mesh networks operate on the principle of device-to-device communication rather than relying on centralized infrastructure. In a mesh network:

  • Direct connections: Devices communicate directly with each other when in range
  • Multi-hop routing: Messages can hop between devices to reach recipients out of direct range
  • Self-organizing: The network automatically reconfigures as devices move in and out of range
  • No central server: Communication continues even when internet or cellular service is unavailable

This architecture makes mesh networks particularly well-suited for disaster scenarios, remote areas, or situations where traditional communication infrastructure has been compromised.

Bluetooth Low Energy Mesh Messaging

Bluetooth Low Energy (BLE) is the most commonly used technology for mesh messaging applications due to its low power consumption and widespread device support. Here’s a basic implementation concept:

java
// Simplified BLE mesh messaging concept
public class MeshMessagingService {
 private BluetoothAdapter bluetoothAdapter;
 private Set<BluetoothDevice> connectedDevices;
 private MessageRouter messageRouter;
 
 public void initialize() {
 bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
 connectedDevices = new HashSet<>();
 messageRouter = new MessageRouter(this);
 
 // Start discovering and connecting to nearby devices
 startDeviceDiscovery();
 }
 
 public void sendMessage(String recipientDeviceId, String message) {
 // Find the recipient in connected devices
 BluetoothDevice recipient = findDeviceById(recipientDeviceId);
 
 if (recipient != null) {
 // Direct message
 sendDirectMessage(recipient, message);
 } else {
 // Route through mesh
 messageRouter.routeMessage(recipientDeviceId, message);
 }
 }
}

Bridgefy Implementation Example

Bridgefy is a commercial mesh messaging platform that provides SDKs for implementing offline messaging. Here’s how you might integrate it into an Android application:

java
// Bridgefy integration example
public class BridgefyMessenger {
 private Bridgefy bridgefy;
 private MeshMessageListener messageListener;
 
 public void initialize() {
 bridgefy = Bridgefy.getInstance(this);
 
 // Set up message listener
 messageListener = new MeshMessageListener() {
 @Override
 public void onMessageReceived(@NonNull MeshMessage message) {
 // Handle incoming message
 processMessage(message);
 }
 };
 
 bridgefy.setMessageListener(messageListener);
 bridgefy.start();
 }
 
 public void sendMessage(String message, String userId) {
 MeshMessage meshMessage = new MeshMessage.Builder()
 .setText(message)
 .setReceiver(userId)
 .build();
 
 bridgefy.send(meshMessage);
 }
}

Advantages of Mesh Network Solutions

Mesh network messaging offers several unique advantages:

  • True offline capability: Works without any internet or cellular connectivity
  • Privacy: Messages are transmitted directly between devices without passing through servers
  • Resilience: Network continues to function even if some devices are offline
  • No carrier dependency: Not subject to cellular network limitations or costs
  • Local communication: Enables messaging in areas without traditional infrastructure

Limitations and Challenges

Despite their advantages, mesh network solutions face several limitations:

  • Range limitations: Direct communication range is typically limited to 30-100 meters depending on the technology
  • Network density: Requires a critical mass of devices for reliable long-distance messaging
  • Battery impact: Constant scanning and communication can significantly impact device battery life
  • Message delivery: No guarantee of message delivery if recipient is not in range
  • Security: Additional considerations for securing device-to-device communications

Hybrid Solutions

For maximum reliability, many applications implement hybrid solutions that combine different communication technologies:

java
public class HybridMessenger {
 private SMSMessenger smsMessenger;
 private MeshMessenger meshMessenger;
 
 public void sendMessage(String recipient, String message) {
 // Try mesh first (no cost, but unreliable)
 if (meshMessenger.isRecipientInRange(recipient)) {
 meshMessenger.sendMessage(recipient, message);
 return;
 }
 
 // Fall back to SMS (reliable but costs)
 smsMessenger.sendMessage(recipient, message);
 }
}

This approach leverages the strengths of each technology while mitigating their individual weaknesses, providing a more robust overall messaging solution.


Sources

  1. Android Developer Documentation — Comprehensive technical reference for SmsManager API and SMS implementation: https://developer.android.com/reference/android/telephony/SmsManager
  2. Android Authority SMS App Tutorial — Step-by-step guide for creating SMS applications with practical implementation details: https://www.androidauthority.com/how-to-create-an-sms-app-721438/
  3. Google Developer Training — Two ways to send SMS with proper permission handling and code examples: https://google-developer-training.github.io/android-developer-phone-sms-course/Lesson 2/2_p_sending_sms_messages.html
  4. Android Broadcast Components — BroadcastReceiver implementation for capturing incoming SMS messages: https://developer.android.com/guide/components/broadcasts
  5. HTTPSMS Project — Android phone as SMS gateway with HTTP API implementation: https://github.com/NdoleStudio/httpsms
  6. SMSGATE Project — Python-based server with GSM modems for self-hosted SMS gateway: https://github.com/pentagridsec/smsgate
  7. Twilio SMS Documentation — Cloud-based SMS gateway with Conversations API for global messaging: https://www.twilio.com/en-us/messaging/channels/sms
  8. Swift SMS Gateway — Web-based group SMS services without coding requirements: https://www.swiftsmsgateway.com/services/group-sms/
  9. Bridgefy Platform — Bluetooth Low Energy mesh network for true offline messaging: https://bridgefy.me/
  10. Kaspersky Mesh Messenger Analysis — Technical comparison of offline messaging applications and security considerations: https://www.kaspersky.com/blog/mesh-messengers/54192/
  11. TechLog360 Offline Apps — List of offline messaging applications with brief descriptions: https://techlog360.com/chat-without-internet/
  12. Mashtips Android Offline Apps — Android-specific offline messaging applications with user statistics: https://mashtips.com/android-offline-messaging-apps/
  13. Reddit Self-Hosted SMS Gateway — Community insights on self-hosted SMS gateways and practical experiences: https://www.reddit.com/r/selfhosted/comments/nqu2u2/selfhosted_sms_gateway_or_something_similar/
  14. Reddit Open-Source SMS Solution — Open-source implementation details for SMS gateways with hardware compatibility: https://www.reddit.com/r/programming/comments/15ayp7x/i_have_created_a_free_and_opensource_solution_for/
  15. StackOverflow Group SMS Implementation — Code example for sending group SMS with Intent on Android: https://stackoverflow.com/questions/28402265/android-sending-group-sms-with-built-in-sms-app

Conclusion

Creating an SMS/MMS-based messenger application that operates without internet connectivity requires careful consideration of different approaches depending on your specific requirements, resources, and use cases. Whether you choose native Android development with SmsManager API, cloud-based SMS gateways like Twilio, self-hosted solutions using Android phones or GSM modems, or mesh network technologies for true offline communication, each approach has its own advantages and limitations.

For developers seeking maximum control and offline capability, the SmsManager API provides direct access to SMS functionality but requires significant development effort. Cloud-based solutions offer scalability and global reach but come with ongoing costs and dependency on third-party services. Self-hosted gateways provide a middle ground with more control than cloud solutions while avoiding the carrier dependency of native implementations. Finally, mesh network solutions enable true offline communication without any infrastructure requirements but face range and reliability limitations.

The optimal approach will depend on factors like your target audience, geographic coverage requirements, message volume, budget constraints, and technical expertise. Many successful implementations combine multiple approaches to create hybrid solutions that leverage the strengths of each technology while mitigating their individual weaknesses.

As messaging continues to evolve and connectivity challenges persist in various regions and scenarios, SMS/MMS-based messenger applications will remain relevant solutions for reliable communication when internet connectivity is unavailable or unreliable.

Authors
Verified by moderation
Create SMS/MMS Messenger App for Offline Group Chat