Android Sms Retriever
Flutter plugin for retrieving OTP code sent in sms automatically and without getting SMS permission in Android. This package has support for Smart Lock credentials, you can use for storing user's phone number and retrieving whenever you want. Read more here
dependencies: android_sms_retriever: ^1.3.0
Use this function to get application signature. App signature should be placed at end of SMS so SmsRetriever API can verify SMS is sent from your server.
String appSignature = await AndroidSmsRetriever.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 AndroidSmsRetriever.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.
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 AndroidSmsRetriever.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.
Start listening for SMS
Use this function to start listening for an incoming SMS. When sms received message will be returned.
String? message = await AndroidSmsRetriever.listenForSms();
Close receiver after getting SMS
Stop listening for SMS. It's better to stop listener after getting message.
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 AndroidSmsRetriever.listenForOneTimeConsent('+9850003001');
Stop one time consent receiver
By default, One time consent receiver will be stopped automatically after receiving sms or timeout. You can also stop it manually by calling
SMS format should be like this :
Your example code is: 123456 appSignature