Всем доброго времени суток, пожалуйста, помогите. Проблема в том, что уведомления мои показываются раньше времени. К примеру, должны показаться минут через 15 (время передаю верно), но появляются они сразу же после выполнения метода (вызывается нажатием кнопки), когда таймер еще отрицательный.
@SuppressLint("NewApi")
public void showNotification(View view) throws ParseException, InterruptedException {
Intent intent = new Intent(getApplicationContext(), NotificatonActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0 , intent, PendingIntent.FLAG_CANCEL_CURRENT);
//Notification Channel
CharSequence channelName = NOTIFICATION_CHANNEL_ID;
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_ID, importance);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 50);
calendar.setTimeZone(TimeZone.getTimeZone("GMT+3"));
date = calendar.getTime();
long when = date.getTime();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.medicine)
.setWhen(when)
.setUsesChronometer(true)
.setContentTitle("ContentTittle")
.setContentText("ContentText");
Notification notification = builder.build();
notificationManager.notify(NOTIFICATION_ID, notification);
NOTIFICATION_ID++;
}
Сборка персонального компьютера от Artline: умный выбор для современных пользователей