sms_sender_background
A Flutter plugin for sending SMS messages with support for dual SIM cards, permission handling, and multi-part messages.
abdulhadinaeem/sms_sender_background open-source repository details.
{"sdk":"flutter"}^2.0.2{"sdk":"flutter"}^4.0.0English project snapshot. Visit GitHub for the latest content.
A Flutter plugin for sending SMS messages with support for dual SIM cards, permission handling, and multi-part messages.
Add this to your package's pubspec.yaml file:
dependencies:
sms_sender_background: ^1.0.5
Add the following permissions to your Android Manifest (android/app/src/main/AndroidManifest.xml):
<uses-permission android:name="android.permission.SEND_SMS"/>
<!-- Optional: Required only for dual SIM support -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Note about READ_PHONE_STATE permission:
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();
}
// Optional: Check and request READ_PHONE_STATE permission for dual SIM support
// If not granted, the plugin will use the default SIM card
bool hasPhoneStatePermission = await smsSender.checkPhoneStatePermission();
if (!hasPhoneStatePermission) {
hasPhoneStatePermission = await smsSender.requestPhoneStatePermission();
}
// 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');
}
}
To send an SMS using a specific SIM card:
// Optional: Request READ_PHONE_STATE permission for dual SIM support
bool hasPhoneStatePermission = await smsSender.checkPhoneStatePermission();
if (!hasPhoneStatePermission) {
hasPhoneStatePermission = await smsSender.requestPhoneStatePermission();
}
await smsSender.sendSms(
phoneNumber: '+1234567890',
message: 'Hello!',
simSlot: 1, // Use second SIM card
);
Important Notes:
READ_PHONE_STATE permissionThe 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...',
);
The plugin provides detailed error information through exceptions:
PlatformException with code "PERMISSION_DENIED" when SMS permission is not grantedPlatformException with code "INVALID_ARGUMENT" when phone number or message is emptyPlatformException with code "SMS_SEND_ERROR" when SMS sending failsFeel free to contribute to this project:
git checkout -b feature/my-new-feature)git commit -am 'Add some feature')git push origin feature/my-new-feature)This project is licensed under the MIT License - see the LICENSE file for details