Диспетчер тревог - планирование нескольких неповторяющихся событий

Как в Android Alarm Manager можно запланировать несколько сигналов тревоги, которые не повторяются и не имеют фиксированных интервалов для повтора? Я не могу использовать функцию setRepeating, так как сигналы тревоги не имеют повторяющегося шаблона.

У меня есть время будильника, хранящееся в таблице базы данных Sqlite, и действие должно выбрать дату и время из этой таблицы и установить сигналы.

] Если мы устанавливаем разные алармы в цикле, то сохраняется только последний. Я прочитал из сообщения: Как можно создать более одного сигнала тревоги?

Он сообщает, что нужно прикрепить уникальный идентификатор к намерению, а затем настроить отдельные события тревоги. Но у меня это не сработало.

Есть ли что-то, что нам нужно добавить в файл манифеста, чтобы позаботиться об этом уникальном идентификаторе?

Код в действии «RegularSchedule» создает только одно тревожное событие:

        while (notifCursor.moveToNext()) {
            Intent intent = new Intent(RegularSchedule.this,
                    RepeatingAlarm.class);

            // The cursor returns first column as unique ID             
            intent.setData(Uri.parse("timer:" + notifCursor.getInt(0)));

            PendingIntent sender = PendingIntent.getBroadcast(
                    RegularSchedule.this, 0, intent, 0);

            // Setting time in milliseconds taken from database table 
            cal.setTimeInMillis(notifCursor.getLong(1));

            AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
        }

Сообщите мне, если еще требуются сведения или фрагменты кода.

Файл манифеста (здесь RepeatingAlarm расширяет BroadcastReceiver):

    

    
    

RepeatingAlarm:

public class RepeatingAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
.......
    // The PendingIntent to launch our activity if the user selects this notification
    Intent notificationIntent = new Intent (context, DisplayReminder.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    mNotificationManager.notify(2425, notification);

24
задан Community 23 May 2017 в 12:06
поделиться