android 收到新短信时,点亮屏幕

                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

猜你喜欢

转载自blog.csdn.net/hffyfdt/article/details/86565200