Notifying when screen is off
Posted
by Al
on Stack Overflow
See other posts from Stack Overflow
or by Al
Published on 2010-02-07T16:36:44Z
Indexed on
2010/03/27
9:03 UTC
Read the original article
Hit count: 269
android
|notification
I'm trying to generate a notification which vibrates the phone and plays a sound when the screen is off (cpu turned off). According to the Log messages, the notification is being sent, but the phone doesn't vibrate or play the sound until I turn the screen on again. I tried holding a 2 second temporary wakelock (PowerManager.PARTIAL_WAKE_LOCK), which I thought would be ample time for the notification to be played, but alas, it still doesn't.
Any pointers to get the notification to run reliably? I'm testing this on an G1 running Android 1.6.
Code I'm using:
notif.vibrate = new long[] {100, 1000};
notif.defaults |= Notification.DEFAULT_SOUND;
notif.ledARGB = Color.RED;
notif.ledOnMS = 1;
notif.ledOffMS = 0;
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.flags |= NOTIF_FLAGS; //static var
if (!screenOn) { //var which updates when screen turns off/on
mWakeLock.acquire(2000);
}
manager.notify(NOTIF_ID, notif);
© Stack Overflow or respective owner