Flutter Android SMS Reader
A Flutter plugin to read SMS messages on Android. Supports inbox, sent, and draft messages with pagination, search, streaming of incoming messages, and permission handling.
β οΈ This plugin is Android-only. iOS does not allow SMS access due to platform restrictions.
π Features
| Feature | Description |
|---|---|
| β Fetch All Messages | Access all SMS on the device |
| β Filter by Type | Fetch only inbox, sent, or draft messages |
| β Pagination Support | Lazy loading of messages |
| β Search SMS | Filter by keyword or phone number |
| β Message Count | Total number of messages per type |
| β Observe New SMS | Stream new incoming messages in real-time |
| β Read Permissions | Auto-handle permission requests |
| β Dual SIM Support (WIP) | Read SIM info (planned) |
| β Export to JSON | Easily convert messages for sharing/storage |
π Installation
Add this to your pubspec.yaml:
dependencies:
android_sms_reader: ^<Latest-Version>
Then run:
flutter pub get
π² Usage
import 'package:android_sms_reader/android_sms_reader.dart';
void init() async {
bool granted = await SmsReader.requestPermissions();
if (!granted) {
// handle permission
return;
}
final messages = await SmsReader.fetchMessages(
type: SmsType.inbox,
start: 0,
count: 50,
query: 'OTP',
);
final count = await SmsReader.getMessageCount(SmsType.sent);
SmsReader.observeIncomingMessages().listen((sms) {
print("Received: ${sms.body}");
});
}
β Android Permissions
Ensure you add these to your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
β iOS Support
iOS does not support reading SMS messages. This plugin returns UnsupportedError on iOS platforms.