SMS Sender Background

A Flutter plugin for sending SMS messages with support for dual SIM cards, permission handling, and multi-part messages.

Features

  • Send SMS messages from your Flutter app
  • Support for dual SIM cards (specify SIM slot)
  • Automatic permission handling (request and check SMS permissions)
  • Support for long messages (automatically splits into multi-part messages)
  • Error handling and status reporting

Getting Started

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  sms_sender_background: ^1.0.6

Android Setup

Add the following permission to your Android Manifest (android/app/src/main/AndroidManifest.xml):

<uses-permission android:name="android.permission.SEND_SMS"/>

Usage

import 'package:sms_sender_background/sms_sender.dart';;

// Create an instance
final smsSender = SmsSender();

// Check SMS permission
bool hasPermission = await smsSender.checkSmsPermission();

// Request permission if needed
if (!hasPermission) {
  hasPermission = await smsSender.requestSmsPermission();
}

// Send SMS
if (hasPermission) {
  try {
    bool success = await smsSender.sendSms(
      phoneNumber: '+1234567890',
      message: 'Hello from Flutter!',
      simSlot: 0, // Optional: specify SIM slot (0 or 1)
    );
    print('SMS sent: $success');
  } catch (e) {
    print('Error sending SMS: $e');
  }
}

Additional Features

Dual SIM Support

To send an SMS using a specific SIM card:

await smsSender.sendSms(
  phoneNumber: '+1234567890',
  message: 'Hello!',
  simSlot: 1, // Use second SIM card
);

Long Messages

The plugin automatically handles long messages by splitting them into multiple parts:

await smsSender.sendSms(
  phoneNumber: '+1234567890',
  message: 'A very long message that will be automatically split...',
);

Error Handling

The plugin provides detailed error information through exceptions:

  • PlatformException with code "PERMISSION_DENIED" when SMS permission is not granted
  • PlatformException with code "INVALID_ARGUMENT" when phone number or message is empty
  • PlatformException with code "SMS_SEND_ERROR" when SMS sending fails

Contributing

Feel free to contribute to this project:

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details

Libraries

sms_sender
A Flutter plugin for sending SMS messages with support for dual SIM cards.
sms_sender_method_channel
sms_sender_platform_interface