2016-10-10 65 views
0
  • 我设置2个警报为上午8点第二天使用下面
  • 手机(三星Galaxy 6)代码已经睡着了,在早上8点的确切时间运行
  • 报警没有在上午8时
  • 运行在8 :上午50点,我按下主页按钮
  • 现在,两个警报都会运行并且通知会显示在主屏幕上。

我希望通知在早上8点出现声音。警报在上午8点运行时缺少什么?报警并在

notificationIntent.putExtra(MyAlarmReceiver.ALARM_ID, alarmID); 
    notificationIntent.putExtra(MyAlarmReceiver.ALARM_TITLE, notifTitle); 
    notificationIntent.putExtra(MyAlarmReceiver.ALARM_SUBTITLE, subTitle); 
    notificationIntent.putExtra(MyAlarmReceiver.NOTIFICATION_TAG, notificationTag); 
    notificationIntent.putExtra(MyAlarmReceiver.NOTIFICATION_ID, notifId); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
    final int sdk = android.os.Build.VERSION.SDK_INT; 
    if (sdk > android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { 
     alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent); 
    } else { 
     alarmManager.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent); 
    } 

回答

0

该平板电脑上使用的Android版本最有可能是棉花糖或更新(API 23)。为了让您的闹钟触发,您必须通过呼叫alarmManager.setExactAndAllowWhileIdle()将它从打盹(空闲模式)优化中排除。

+1

谢谢。让我试着更新。是的,它是6.x – GJain