flutter_background_messenger
A Flutter plugin for sending SMS messages in the background on Android devices.
Features
- Send SMS messages from Flutter apps
- Handle SMS permissions
- Background message sending capability
Getting Started
Add this to your package's pubspec.yaml
file:
dependencies:
flutter_background_messenger: ^0.0.1
Platform Specific Setup
Android
- Add the following permissions to your
AndroidManifest.xml
file:
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
- Ensure your minSdkVersion is set to 21 or higher in your
android/app/build.gradle
file:
android {
...
defaultConfig {
...
minSdkVersion 21
}
}
Usage
To send an SMS message, use the following code:
import 'package:flutter_background_messenger/flutter_background_messenger.dart';
class MessagingExample {
final messenger = FlutterBackgroundMessenger();
Future<void> sendSMS() async {
try {
final success = await messenger.sendSMS(
phoneNumber: '+1234567890',
message: 'Hello from Flutter Background Messenger!',
);
if (success) {
print('SMS sent successfully');
} else {
print('Failed to send SMS');
}
} catch (e) {
print('Error sending SMS: $e');
}
}
}