У меня возникла необходимость использовать для вызова уведомлений broadcast, и у меня возникла проблема: я хочу, чтобы уведомления приходили каждый час, но с TICK они поступают каждую минуту. Есть ли альтернативный объект, или как можно изменить его параметры? Заранее спасибо, желательно продемонстрировать эти "махинации".
Метод вызова уведомлений:
public void showNotifications() {
this.registerReceiver(mTimeBroadCastReceiver, new IntentFilter("android.intent.action.TIME_HOUR"));
Notification.Builder builder = new Notification.Builder(getApplicationContext());
Intent intent = new Intent(getApplicationContext(), Base.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder
.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setTicker("Новое уведомление")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("Прошёл час")
.setContentText("Пора ставить оценку");
Notification notification = builder.build();
notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
NM.notify(NOTIFICATION_ID, notification);
broadcast:
public class TimeBroadcastReceiver extends BroadcastReceiver {
private final int NOTIFICATION_ID = 104;
private AlarmManager manager;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onReceive(Context context, Intent intent) {
manager= (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent fakeIntent = PendingIntent.getActivity(context,0,new Intent(context,Notify.class),PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 1);
long time = calendar.getTimeInMillis();
manager.setRepeating(AlarmManager.RTC_WAKEUP, time,
60000, fakeIntent);
}
}
Попробуйте добавить еще одни 0, если не ошибаюсь 1000 = 1 секунде
manager.setRepeating(AlarmManager.RTC_WAKEUP, time, 600000, fakeIntent);
Сборка персонального компьютера от Artline: умный выбор для современных пользователей