0

私のアプリケーションでは、異なる日付に別のアラームを設定したいと考えています。このコードで可能ですか:

//For Broadcast Alarm
                alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
                Intent in = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
                pendingIntentOfTwoMonth = PendingIntent.getBroadcast(this, 0, in, 0);

                // for the GST 20 June 2011
                Calendar calendar_GST_18_June_2011 = Calendar.getInstance();
                calendar_GST_18_June_2011.setTimeInMillis(System.currentTimeMillis());
                calendar_GST_18_June_2011.set(2011, 5, 18, mHour, mMinute, 0);
                alarmManager.set(AlarmManager.RTC_WAKEUP,   calendar_GST_18_June_2011.getTimeInMillis(), pendingIntentOfTwoMonth); 

                // for the GST 17 August 2011
                Calendar calendar_GST_17_August_2011 = Calendar.getInstance();
                calendar_GST_17_August_2011.setTimeInMillis(System.currentTimeMillis());
                calendar_GST_17_August_2011.set(2011, 7, 17, mHour, mMinute, 0);
                alarmManager.set(AlarmManager.RTC_WAKEUP,  calendar_GST_17_August_2011.getTimeInMillis(), pendingIntentOfTwoMonth);

                // for the GST 19 October 2011
                Calendar calendar_GST_19_October_2011 = Calendar.getInstance();
                calendar_GST_19_October_2011.setTimeInMillis(System.currentTimeMillis());
                calendar_GST_19_October_2011.set(2011, 9, 19, mHour, mMinute, 0);
                alarmManager.set(AlarmManager.RTC_WAKEUP,  calendar_GST_19_October_2011.getTimeInMillis(), pendingIntentOfTwoMonth);

                // for the GST 17 December 2011
                Calendar calendar_GST_17_December_2011 = Calendar.getInstance();
                calendar_GST_17_December_2011.setTimeInMillis(System.currentTimeMillis());
                calendar_GST_17_December_2011.set(2011, 11, 17, mHour, mMinute, 0);
                alarmManager.set(AlarmManager.RTC_WAKEUP,  calendar_GST_17_December_2011.getTimeInMillis(), pendingIntentOfTwoMonth);

                // for the GST 18 February 2012
                Calendar calendar_GST_18_February_2012 = Calendar.getInstance();
                calendar_GST_18_February_2012.setTimeInMillis(System.currentTimeMillis());
                calendar_GST_18_February_2012.set(2012, 1, 18, mHour, mMinute, 0);
                alarmManager.set(AlarmManager.RTC_WAKEUP,  calendar_GST_18_February_2012.getTimeInMillis(), pendingIntentOfTwoMonth);

                // for the GST 27 April 2012
                Calendar calendar_GST_27_April_2012 = Calendar.getInstance();
                calendar_GST_27_April_2012.setTimeInMillis(System.currentTimeMillis());
                calendar_GST_27_April_2012.set(2011, 3, 27, mHour, mMinute, 0);
                alarmManager.set(AlarmManager.RTC_WAKEUP,  calendar_GST_27_April_2012.getTimeInMillis(), pendingIntentOfTwoMonth);

ありがとう。

4

1 に答える 1

1

いいえそうではありません。最後に作成したアラームは 1 つだけです。これは、PendingIntent が同じであるためです。複数のアラームを取得するには、一意の PendingIntents を使用する必要があります。AlarmManager と Notifications の API ドキュメントを読むことをお勧めします。

于 2011-12-28T11:49:24.113 に答える