android_sms_retriever 1.0.0 android_sms_retriever: ^1.0.0 copied to clipboard
Flutter plugin for retrieving OTP code sent in sms automatically and without getting SMS permission in Android.
Android Sms Retriever #
Flutter plugin for retrieving OTP code sent in sms automatically and without getting SMS permission in Android. You can find full API document here
Getting Started #
Install
dependencies:
android_sms_retriever: ^1.0.0
Import
import 'package:android_sms_retriever/android_sms_retriever.dart';
App signature #
To retrieve a app signature. App signature should be placed at end of SMS so SmsRetriever API can verify SMS is sent from your server.
String appSignature = await SmsRetriever.getAppSignature();
Request phone number #
You can request android to open a dialog with user's phone numbers, then user can select one.
String phoneNumber = await ArsSmsRetriever.requestPhoneNumber();
Store phone number #
You can store user's phone number to use later, For example: When user uninstalls application and installs again. You should pass your application's website URL and phone number to this function.
await ArsSmsRetriever.storePhoneNumber('https://arsam.me','09027777254');
Retrieve stored phone number #
To retrieve stored phone number use this function. You should pass your application's website URL to this function.
String phoneNumber = await ArsSmsRetriever.retrieveStoredPhoneNumber('https://arsam.me');
Delete stored phone number #
To delete stored phone number use this function. You should pass your application's website URL and phone number to this function.
await ArsSmsRetriever.deleteStoredPhoneNumber('https://arsam.me','09027777254');
Start listening for SMS #
To start listening for an incoming SMS
String smsCode = await ArsSmsRetriever.startSmsListener();
Close receiver after getting SMS #
Stop listening after getting the SMS
ArsSmsRetriever.stopSmsListener();
Request one time SMS consent #
Using this function, when sms received android will ask user to let application use message and extract code, even if sms message does not contain application signature. You can pass sender phone number in order to detect messages sent from specific sender.
String smsCode = await ArsSmsRetriever.requestOneTimeConsentSms('+9850003001');
Note
SMS format should be like this :
Your example code is: 123456
appSignature