This is an ionic project that uses the PhoneCallTrap cordova plugin and a BroadcastReceiver to receive the incoming phone number when the phone is ringing.
- Android
- ionic v1
- ionic v3
The project uses a BroadcastReceiver which has an onReceive method implemented. This method is called whenever the phone changes call state. All the possible call states are: IDLE, OFFHOOK and RINGING.
Phone goes into RINGING state → the onReceive method gets called and sends the incoming phone number to the CallStateListener → The CallStateListener, also triggered by the state change, sends the phone number as PluginResult to the PhoneCallTrap cordova plugin → ionic gets the call state as well as the phone number and prints them on the console.
Run these commands inside the folder of your ionic project:
(if you already have cordova and android platform installed start from the 3rd command)
npm install -g cordovacordova platform add androidcordova plugin add antonis.phonecalltrap
Phone permissions must be given to the app for the plugin to work properly.