readotp
A Flutter plugin to read incoming SMS (OTP) messages on the device as a broadcast stream.
Usage
-
Request SMS Permission
- Use the
permission_handler
package to request SMS permissions at runtime. - On Android, add the following to your
AndroidManifest.xml
:<uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" />
- Use the
-
Create and Start the Plugin
final readOtp = ReadOtp(); await Permission.sms.request(); // Request permission before starting readOtp.start();
-
Listen to the SMS Stream
readOtp.smsStream.listen((sms) { print(sms.body); print(sms.sender); print(sms.timeReceived); });
-
Dispose When Done
readOtp.dispose();
That's all you need to do!
For a complete example, see example/lib/main.dart
.