Я пытаюсь запланировать уведомление на 2 часа от текущего фрагмента, но метод onRecieve в alarmreciever вообще не вызывается ...
DateFragment
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
AlarmManager alarms = (AlarmManager) Objects.requireNonNull(getActivity()).getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent("notif.alarm.DISPLAY_NOTIF");
PendingIntent operation = PendingIntent.getBroadcast(getContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
assert alarms != null;
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 10);
alarms.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), operation) ;
}
AlarmReciever
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Map<String, String> data = new HashMap<>();
data.put("call_frag","0");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(Constants.CHANNEL_ID, Constants.CHANNEL_NAME, importance);
mChannel.setDescription(Constants.CHANNEL_DESCRIPTION);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400});
assert mNotificationManager != null;
mNotificationManager.createNotificationChannel(mChannel);
}
MyNotificationManager.getInstance(context).displayNotification(data);
}
}
Манифест
<receiver android:name=".networks.AlarmReceiver">
<intent-filter>
<action android:name="notif.alarm.DISPLAY_NOTIF"/>
</intent-filter>
</receiver>
Пожалуйста, помогите мне отладить проблему.