jefflinwood / twilio_client_phonegap

Phonegap plugins for the Twilio Client iOS and Android SDKs
MIT License
59 stars 53 forks source link

Background Incoming call usage (Android) #41

Open ari3l opened 8 years ago

ari3l commented 8 years ago

The twilio android SDK docs says :

"Incoming calls are first detected by the Twilio Client service, which then hands them to your app to handle. However, your application may be in the background and its Activities paused or killed, so the library needs a mechanism to ensure your app gets restarted properly and hand it the incoming call. In fact, the same mechanism is used to notify your app about incoming calls when it's in the foreground."

My question is, how do I receive incoming calls while the app is killed / paused?

jefflinwood commented 8 years ago

Hi,

Is your question whether it works in your app, or how it works in the plugin?

ari3l commented 8 years ago

My question is how does it work in the plugin?

tombuyse commented 8 years ago

Twilio provides a background service with their SDK that enables the plugin to receive incoming call events.

I'm also having some problems with this service though. Everything works fine for a few hours while the background service is still active, but when the device goes into deep sleep calls aren't being received anymore.

I guess the only solution would be to implement a certain wakelock to keep the phone awake? Though this might not be the best solution for the battery consumption.

I have tested this on android 5.0

jefflinwood commented 8 years ago

The plugin registers with the Twilio background service, which then fires off a pending intent that triggers an event in the plugin that you can listen for in Javascript. It doesn't work when the app is completely killed off. I'm not sure if that's possible - it will bring the app to the front if the app is running in the background, and a call comes in.

You could potentially put in a wakelock, but I don't think that's a great solution for the user, because the battery life would be terrible (and your app would probably be blamed in the energy meter).