2016-10-10 37 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