Как я могу установить несколько предупреждений в Android?

До сих пор и благодаря этому веб-сайту, я смог настроить предупреждение, которое будет настроено и активно, даже если я повернусь своего телефона.

Теперь, я настроил предупреждение для показа напоминания для события A, и мне нужно приложение для установки другого предупреждения для показа другого напоминания для события B.

Я должен делать что-то не так, потому что это только увольняет напоминание за событие A. Кажется, что когда-то настроенный, любое другое предупреждение понято как тот же.:-(

Вот деталь того, что я делаю на двух шагах:

1) От действия я поставил будильник, который в определенное время и дату назовет получатель

                Intent intent = new Intent(Activity_Reminder.this,
                        AlarmReceiver_SetOnService.class);

                intent.putExtra("item_name", prescription
                        .getItemName());
                intent
                        .putExtra(
                                "message",
                                Activity_Reminder.this
                                        .getString(R.string.notif_text));
                intent.putExtra("item_id", itemId);
                intent.putExtra("activityToTrigg",
                        "com.companyName.appName.main.Activity_Reminder");

                PendingIntent mAlarmSender;

                mAlarmSender = PendingIntent.getBroadcast(
                        Activity_Reminder.this, 0, intent, 0);

                long alarmTime = dateMgmt.getTimeForAlarm(pickedDate);
                Calendar c = Calendar.getInstance();
                c.setTimeInMillis(alarmTime);
                // Schedule the alarm!
                AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
                am.set(AlarmManager.RTC_WAKEUP, alarmTime + 15000,
                        mAlarmSender);

2) От получателя я называю сервис

        Bundle bundle = intent.getExtras();
        String itemName = bundle.getString("item_name");
        String reminderOrAlarmMessage = bundle.getString("message");
        String activityToTrigg = bundle.getString("activityToTrigg");
        int itemId = Integer.parseInt(bundle.getString("item_id"));
        NotificationManager nm = (NotificationManager) context.getSystemService("notification");
        CharSequence text = itemName + " "+reminderOrAlarmMessage;
        Notification notification = new Notification(R.drawable.icon, text,
                System.currentTimeMillis());
        Intent newIntent = new Intent();
        newIntent.setAction(activityToTrigg);
        newIntent.putExtra("item_id", itemId);
        CharSequence text1= itemName + " "+reminderOrAlarmMessage;
        CharSequence text2= context.getString(R.string.notif_Go_To_Details);
        PendingIntent pIntent = PendingIntent.getActivity(context,0, newIntent, 0);
        notification.setLatestEventInfo(context, text1, text2, pIntent);
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.defaults = Notification.DEFAULT_ALL;
        nm.notify(itemId, notification);

Заранее спасибо,

monn3t

36
задан monn3t 17 July 2010 в 21:26
поделиться

1 ответ

Хорошо, когда вы устанавливаете PendingIntent, вы должны назначить ему уникальный идентификатор на случай, если вы захотите идентифицировать его позже (для изменения / отмены)

static PendingIntent    getActivity(Context context, int requestCode, Intent intent, int flags) 
//Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent).
static PendingIntent    getBroadcast(Context context, int requestCode, Intent intent, int flags) 
//Retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().

Запрос код - это этот идентификатор.

В вашем коде вы продолжаете сбрасывать SAME PendingIntent, вместо этого каждый раз используйте другой RequestCode.

PendingIntent pIntent = PendingIntent.getActivity(context,uniqueRQCODE, newIntent, 0);

Это должно быть целое число, я полагаю, у вас есть первичный идентификатор ( itemId ), который может идентифицировать аварийный сигнал A от аварийного сигнала B.

76
ответ дан 27 November 2019 в 05:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: