私は2つのアラームが設定されています.1つは通知用で、もう1つはいくつかのタスクを実行します。私の問題は、アラームが1つしか動作していないようだ(通知サービス1、最初のアラームセット)。他のアラームは決して消えません。ここに私のコードです:保留中のインテントが2つあるアラームマネージャーは1つだけですか?
Intent myIntent1 = new Intent(getApplicationContext(), NotificationService.class);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, myIntent1, 0);
AlarmManager alarmManager1 = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(System.currentTimeMillis());
long frequency1 = 30 * 1000; // in ms
alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), frequency1, pendingIntent);
// Set alarm to fire go to Next day everyday at the same time
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 14); // For 1 PM or 2 PM
calendar.set(Calendar.MINUTE, 57);
calendar.setTimeInMillis(System.currentTimeMillis());
Intent myintent = new Intent(getApplicationContext(), AlarmNextDayService.class);
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getService(getApplicationContext(), 11, myintent,0);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pi);
何か提案は大歓迎です。私は他のソースを見てきましたが、今まで私にとっては何も働いていません。 私も次のようにマニフェストファイルにアラームpermisisonを追加しました:
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
はあなたがHOUR_OF_DAYとMINUTEを設定しているが、それらあなたがいることがsetTimeInMillis(システムを呼び出すことによって上書きあなた
それぞれのインテントに一意の識別子を追加しようとしましたか?Intent intent = new Intent( "uniqId"、null、context、Receiver.class); –
マニフェストに2番目の 'Service'がリストされていますか?また、時と分を設定した後、 'Calendar'インスタンスを現在の時刻にリセットしていることに気付いていますか?不正確なアラームは、その間隔ではかなり離れている可能性があることにも留意してください。 –
が問題だったことが判明した@MikeM。あなたはそれを答えとして書くことができますか? – LoveMeow