2

What I want:

I am developing one app where I want to display dialog / popup on incoming call.

I have observed in log that there is slight delay between my activity start on incoming call and phone screen getting on. First activity gets fired and then phone screen gets on.

So I want to display this dialog after the phone screen gets on. In short I want to wait till phone gets on.

What I Tried:

  • I have used Asynctask in BroadcastReceiver

    protected Boolean doInBackground(Void... params) {
    
       PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        isScreenOn = powerManager.isInteractive();
        return  isScreenOn;
    }    
    

and followed this answer. But it is giving me compile time exception

unhandled exception java.util.concurrent.executionexception even after searching a lot on google I was not able to solve it. So I used another approach.

  • I have created another* broadcast receiver for phone screen status as per this link

(*Note I already have incoming call broadcast receiver)

But I am not able to figure out how incoming call broadcast receiver will communicate to phone screen broadcast receiver and wait till phone screen gets on.

  • I have even tried to add intent action in existing broadcast receiver but again dont know how to wait till phone screen gets on.

Any pointers/suggestions?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
PeterB
  • 313
  • 4
  • 19

1 Answers1

0

After Struggling a lot on this issue, finally able to solve it. Posting the answer if anybody else struggling for similar issue.

case TelephonyManager.CALL_STATE_RINGING: //Incoming Call Ringing

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    //Calling activity to show dialog / popup window.
                }
            }, 1000);

It was that simple. Phew!!

PeterB
  • 313
  • 4
  • 19