gpt4 book ai didi

android - 使用 PowerManager.WakeLock 延长屏幕唤醒持续时间

转载 作者:行者123 更新时间:2023-11-29 01:54:09 26 4
gpt4 key购买 nike

我正在使用 PowerManager.WakeLock 在出现通知时唤醒我的屏幕...

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, getClass().getName());

//Acquire the lock
wl.acquire();

NotificationCompat.Builder nb = new NotificationCompat.Builder(context);
nb.setContentTitle("Title");
nb.setContentText("This is a notification test.");
nb.setSmallIcon(R.drawable.ic_launcher);
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

final Intent notificationIntent = new Intent(context.getApplicationContext(), ShowReminderActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

final PendingIntent contentIntent = PendingIntent.getActivity(context.getApplicationContext(), 0, notificationIntent, 0);
nb.setContentIntent(contentIntent);

Notification notification = nb.getNotification();
notification.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify(0, notification);

//Release the lock
wl.release();

这会在收到通知时唤醒屏幕,但屏幕唤醒只是眨眼。我尝试了 wl.acquire(Long.valueOf(5000)) 但这并没有延长屏幕唤醒时间。

如何延长屏幕唤醒时间?

谢谢!

最佳答案

try {
Thread.sleep(1000);//or however long this is one second
} catch (InterruptedException e) {
e.printStackTrace();
}

关于android - 使用 PowerManager.WakeLock 延长屏幕唤醒持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16227645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com