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
);
Uses the flags is the right way to do it, using the power manager is wrong.
Your requests sound conflicting to me: you say you want the activity to appear on top of the lock screen (in fact we don't do that, we hide the lock screen so the activity can be seen), while at the same time you want the user to first have to unlock the device.
If you are thinking you want the user to see a notification before unlocking the device to see your activity... I really think you don't want that. The notification is very small (in the status bar at the top), and the next that is shown while posting it is very transient. This is not going to be a good experience for someone who heard their phone beep or buzz and is pulling it out to see what is going on.
You should use whatever combination of the window flags that make sense for your app. You can get pretty much any reasonable behavior between the various combinations of them. These are used for the alarm clock, incoming call UI, etc.