[英]Turn the screen backlight on when my application receive notification
当我的应用程序收到通知时,我需要打开屏幕背光。 我得到了声音,LED指示灯亮起并震动了,但屏幕保持关闭状态。
我尝试使用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();
但是没有结果。
通知代码如下:
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);
}
通知出现在状态栏中时如何打开屏幕? 为此,我需要添加什么?
感谢您的任何建议和帮助。
尝试这个
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();
并且不要忘记释放它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.