Reputation: 1239
I need to turn the screen backlight on when my application receive notification. I get the sound, LED light on and vibration but the screen stays off.
I tried using PowerManager:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
..screen will stay on during this section..
wl.release();
But without result.
The notification code looks like:
public void showNotification( String contentTitle, String contentText ) {
int icon = R.drawable.notification;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, contentTitle, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_LIGHTS;
Intent notificationIntent = new Intent(this, myapp.class);
Context context = this.getApplicationContext();
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
NotificationManager nm = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(300);
notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.sonar_ping);
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB = 0x00000000;
notification.ledOnMS = 0;
notification.ledOffMS = 0;
nm.notify(1, notification);
}
How to turn on the screen when the notifications appear in the status bar? What do I need to add in this code to achieve that?
Thanks for any advice and help.
Upvotes: 0
Views: 1570
Reputation: 2596
Try this
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE, "WakeLock");
wakeLock.acquire();
and don`t forget to release it.
Upvotes: 4