Listen Incoming SMS
Setup
Requires RECEIVE_SMS
permission.
To listen to incoming SMS add the RECEIVE_SMS
permission to your AndroidManifest.xml
file and register the BroadcastReceiver
.
Usage
1. Create a top-level static function to handle incoming messages when app is not is foreground.
Avoid heavy computations in the background handler as Android system may kill long running operations in the background.
2. Call listenIncomingSms
with a foreground MessageHandler
and pass in the static backgrounMessageHandler
.
Multipart message will be grouped together and delivered as a single SMS to the listenIncomingSms() function.
Preferably should be called early in app lifecycle.
3. As of the 1.12
release of Flutter, plugins are automatically registered. This will allow you to use plugins as you normally do even in the background execution context.
4. If you do not wish to receive incoming SMS when the app is in background, just do not pass the onBackgroundMessage
parameter.
Alternatively if you prefer to expecility disable background execution, set the listenInBackground
flag to false
.
Last updated