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

来源:互联网 发布:slide.js插件用法 编辑:程序博客网 时间:2024/04/29 12:14
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属性。
原创粉丝点击