I'm receiving an incoming C2DM notification while the screen is locked. I'd like to wake up the screen and display the notification message on top of the lock screen using an Activity. I'm launching the notification Activity from my C2DM BroadcastReceiver as follows:
Intent new_intent= new Intent().setClass( context, EIAlertDialog.class );
new_intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
new_intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
context.startActivity( new_intent );
and within the notification Activity's onCreate method, I wake up the screen as follows:
PowerManager powerManager= (PowerManager)getSystemService( Context.POWER_SERVICE );
if (!powerManager.isScreenOn()) {
mWakeLock= powerManager.newWakeLock(
PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP,
"My Tag" )
mWakeLock.acquire();
}
The screen is woken up, but the notification Activity is not visible until I unlock the screen.
I realize that I can avoid the lock screen with the code below, but that is not desired. I want the user to unlock the phone, only if he/she is interested in reading/responding to the notification.
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
);