1. 程式人生 > >android 收到新短信時,點亮屏幕

android 收到新短信時,點亮屏幕

http true 基礎 set tps power empty details sem

1.在NotificationTransaction.java裏增加新的變量如下:
private static final int WAKE_LOCK_TIMEOUT = 5000;
private static PowerManager.WakeLock mWakeLock;
2.修改NotificationTransaction.updateNewMessageIndicator方法
public static void updateNewMessageIndicator(Context context, boolean isNew) {
Log.d(TAG, "updateNewMessageIndicator, isNew = " + isNew);
SortedSet accumulator =
new TreeSet(INFO_COMPARATOR);
Set threads = new HashSet(4);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "updateNewMessageIndicator");
mWakeLock.setReferenceCounted(true);
int count = 0;
count += accumulateNotificationInfo(
accumulator, getMmsNewMessageNotificationInfo(context, threads));
count += accumulateNotificationInfo(
accumulator, getSmsNewMessageNotificationInfo(context, threads));
cancelNotification(context, NOTIFICATION_ID);
if (!accumulator.isEmpty()) {
accumulator.first().deliver(context, isNew, count, threads.size());
}
mWakeLock.acquire(WAKE_LOCK_TIMEOUT);
}
3.根據自己的需要來定義WAKE_LOCK_TIMEOUT的時間長短。
如果需要按鍵燈和屏幕都亮,則修改PowerManager.SCREEN_BRIGHT_WAKE_LOCK屬性為PowerManager.FULL_WAKE_LOCK屬性。

再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!https://blog.csdn.net/jiangjunshow

android 收到新短信時,點亮屏幕