Skip to content

nousath/advanced_sms_log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“© advanced_sms_log

● Android SMS log reader (inbox/sent/etc)
● Real-time incoming SMS listener (stream)
● OTP read (User Consent API) β€” Play-safe

Platforms: βœ… Android | ❌ iOS (not supported by iOS APIs)


πŸ“Έ Screenshots

advanced_sms_log screenshot


✨ Features

βœ… 1) SMS log reader

  • Read SMS logs:
    • Inbox / Sent / Draft / Outbox / Failed / Queued / All
  • Filters:
    • address, bodyContains, threadId, date range from/to
  • Pagination:
    • limit + offset
  • Best-effort SIM info:
    • subId (if available on device/ROM)

βœ… 2) Real-time listener (stream)

  • Incoming SMS events:
    • Works while your app process is alive
    • Uses BroadcastReceiver for SMS_RECEIVED
  • Optional store change watcher:
    • ContentObserver on content://sms
    • Emits store_changed events (and can fetch latest message if READ_SMS granted)

βœ… 3) Send SMS + status callbacks (optional)

  • Send SMS through this plugin (uses SmsManager)
  • Get sent / delivered callbacks via events stream
    (Status callbacks are only guaranteed for messages sent via this plugin.)

βœ… 4) OTP read (recommended for Play)

  • OTP via SMS User Consent API
  • No READ_SMS / RECEIVE_SMS runtime permission required
  • Provide a regex like \b\d{4,8}\b

⚠️ Google Play policy note (important)

Google Play restricts use of SMS permissions (like READ_SMS, RECEIVE_SMS).
If your app does not qualify under Play policies, do not include those permissions.
Use OTP via User Consent / SMS Retriever instead.


πŸ“¦ Install

dependencies:
  advanced_sms_log: ^1.0.1

πŸ€– Android setup

Permissions (only if you use full logs + incoming SMS receiver)

Add to your app android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<!-- Only if you send SMS via plugin -->
<uses-permission android:name="android.permission.SEND_SMS" />

If you publish on Google Play, ensure policy compliance before requesting SMS permissions.

OTP dependency

This plugin uses Google Play Services Auth API Phone for OTP consent.
The dependency is already included in the plugin's Android Gradle config.


πŸš€ Usage

1) Read SMS logs

import 'package:advanced_sms_log/advanced_sms_log.dart';

final ok = await AdvancedSmsLog.requestSmsLogPermission();
if (!ok) return;

final items = await AdvancedSmsLog.getSms(
  box: SmsBox.inbox,
  limit: 50,
  offset: 0,
  bodyContains: 'otp',
);

for (final m in items) {
  print('${m.address}  ${m.date}  ${m.body}');
}

2) Real-time incoming SMS listener

await AdvancedSmsLog.startIncomingListener(
  useBroadcast: true,
  useObserver: true,
);

final sub = AdvancedSmsLog.events.listen((e) {
  if (e.type == SmsEventType.received) {
    final sms = e.sms;
    print('Incoming: ${sms?.address} -> ${sms?.body}');
  }
});

// later...
// await AdvancedSmsLog.stopIncomingListener();
// await sub.cancel();

3) OTP read (User Consent)

await AdvancedSmsLog.startOtpUserConsent(
  otpRegex: r'\b\d{4,8}\b',
);

AdvancedSmsLog.events.listen((e) {
  if (e.type == SmsEventType.otp) {
    print('OTP: ${e.otp}');
    print('Message: ${e.message}');
  }
});

4) Send SMS (optional)

final ok = await AdvancedSmsLog.requestSendPermission();
if (!ok) return;

final sent = await AdvancedSmsLog.sendSms(
  to: '+919999999999',
  message: 'Hello from advanced_sms_log',
);

print('sendSms(): $sent');

πŸ“š API

Enums

  • SmsBox: inbox, sent, draft, outbox, failed, queued, all

Models

  • SmsLog
    • id, address, body, date, dateSent, threadId, type, read, seen, subId

Events (single stream)

  • received β†’ SmsLog
  • store_changed β†’ SmsLog? (if READ_SMS granted, we include latest)
  • sent_status β†’ {messageId, kind, status, resultCode}
  • otp β†’ {otp, message}
  • error β†’ {error}

πŸ“„ Docs

  • doc/USAGE.md
  • doc/ARCHITECTURE.md

β˜• Sponsor a cup of tea

If this package saves you development time, consider supporting my work.

Sponsor

https://github.com/sponsors/nousath


🧾 Changelog

See CHANGELOG.md.

About

Android SMS log reader with real-time incoming stream, optional store observer, SMS send status callbacks, and OTP via SMS User Consent API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors