Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我的应用程序收到通知时,打开屏幕背光_Java_Android - Fatal编程技术网

Java 当我的应用程序收到通知时,打开屏幕背光

Java 当我的应用程序收到通知时,打开屏幕背光,java,android,Java,Android,当我的应用程序收到通知时,我需要打开屏幕背光。 我听到声音、LED灯亮起和振动,但屏幕一直关闭 我尝试使用PowerManager: PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); ..scree

当我的应用程序收到通知时,我需要打开屏幕背光。 我听到声音、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();
别忘了释放它。

试试这个

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();

别忘了把它发布。

可能的副本可能的副本谢谢。这就是我一直在寻找的解决方案。
PowerManager.FULL\u WAKE\u LOCK
已被弃用。没有它怎么办?大卫,你可以使用
PowerManager.SCREEN\u BRIGHT\u WAKE\u LOCK
PowerManager.SCREEN\u DIM\u WAKE\u LOCK
谢谢。这就是我一直在寻找的解决方案。
PowerManager.FULL\u WAKE\u LOCK
已被弃用。没有它怎么办?大卫,你可以使用
PowerManager.SCREEN\u BRIGHT\u WAKE\u LOCK
PowerManager.SCREEN\u DIM\u WAKE\u LOCK