首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PowerManager.WakeLock延长屏幕唤醒时间

使用PowerManager.WakeLock延长屏幕唤醒时间
EN

Stack Overflow用户
提问于 2013-04-26 10:07:36
回答 1查看 723关注 0票数 2

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

代码语言:javascript
复制
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)),但这并没有延长唤醒的屏幕。

如何延长屏幕唤醒时长?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-26 10:14:22

代码语言:javascript
复制
try {
            Thread.sleep(1000);//or however long this is one second
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16227645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档