Praveen Kumar C Praveen Kumar C - 1 year ago 93
Android Question

Android O : PHONE_STATE broadcast limitation

I have been trying to do something similar to truecaller app, where my app is supposed to show a screen after a call gets hung up. Was achieving this by registering

implicit broadcast in the

But it is not working if I change the app to target Android O, because of the Android O broadcast limitation, and I'm trying to figure out an alternative solution to this use case.

Alternative solutions suggested in android docs:
Job scheduler
or register a

Job scheduler: Because of the
Job scheduler
optimizations there will be some delay to receive the callback. So it will affect the user experience if our app screen is shown a few min after the phone call and polling to check for new call logs every few seconds causes battery drain issue.

Register service with context in Java: I want the behavior to work even if the app is not active or alive. This will not work if the system kills the

Register a Foreground Service: This requires a notification to be shown to the user all the time, which would be spam the user, and running a service 24/7 consumes lots of resources which defeats the whole purpose of broadcast limitation.

Please suggest an alternate solution so that the user experience remains the same.

Thanks in advance

Answer Source

As there is NO proper solution to read the PHONE_STATE from Android O. The best alternative we can go for is to trigger a job on new call log entry from the content provider. By this, the behaviour is maintained of showing a screen(with a few sec of delay) after the call ends.

NOTE : The disadvantage is we cannot get the state of the phone call(Ringing or off_the_hook etc.,). The call back will only be received after the new call log has been added to the System DB.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download