A flutter plugin to handle Phone Call state and execute a Dart callback in background.
This package is under development and since I'm not keen on native Android development, there may be a lot of work to do, so any PR are welcome.
Unfortunately I'm not familiar with IOS development neither with Switf/ObjC languages, so if you wish to help any PR will be welcome.
Add the following permissions to your
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_CALL_LOG" />
Also, apparently it is necessary to register the broadcast receiver manually, otherwise an error will be throw saying that our receiver does not exist inside the app:
<receiver android:name="me.leoletto.caller.CallerPhoneServiceReceiver" android:exported="false"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver>
All you need to start using our package after installing it, is defining a callback which must be a top level function or static function, that will be called by our plugin when any incoming call events are detected.
void callerCallbackHandler(CallerEvent event, String number, int duration)
This callback handler must accept 3 arguments:
CallerEvent: The event type detect by our plugin in background.
Number: The incoming number that is triggering the phone state call.
duration: An integer that represents the duration of the call in seconds.
CallerEvent is an
enum with four possible values:
|incoming||Indicates an incoming call.|
|outgoing||Indicates an outgoing call.|
Since all this process happens in background in a Dart Isolate, there's no guarantee that the current
OS will call the registered callback as soon as an event is triggered or that the callback will ever be called at all,
each OS handle background services with different policies. Make sure to ask user permission before calling the
method of our plugin. Check the example to see a simple implementation of it.
If you were using the previous version 1.x.x of this package, be aware that some breaking changes have been made.
- Intermediate events won't be fired anymore, a single event will be fired when the call is ended, indicating the type (incoming/outgoing), the duration and the phone number.