アラームの追加、表示、キャンセルができるアプリを作りたいです。そのためのデータベースを設計しました。新しいアラームの表示と作成は完全に機能します。
しかし、問題はアラームをキャンセルすることです。すべてのアラームはpendingIntent、異なるで同じものによって設定されrequest_codeます。はrequest_codeデータベース エントリ (ID フィールドなど) から取得されます。この方法を使用するcancel(pendingIntent)と、すべてのアラームがキャンセルされます。しかし、特定のアラームで特定のアラームをキャンセルしたいだけですrequest_code。これが私のアラームコードの作成です:
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, 0);
Intent intent = new Intent(this, d1_on.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, user_id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
CANCELボタンをクリックすると、user_id. 次に、その行をデータベースから削除します。大丈夫ですが、request_codeuser_id を設定して特定のアラームを停止したいと思います。
pendingIntentまたは、クラスで作成したalarmActivityクラスをクラスからキャンセルする方法を教えてくださいalarmReceiver。