2016-07-12 13 views
0

私はアラームを設定することができますアプリを作っている。それは実際に動作しますが、ただ1回です。 と私は複数回行う必要があります。クラスのスケジュールアラームをしようとしています。Androidのアラームマネージャは、特定の日にアラームを設定し、すべての週をそれらを繰り返す

たとえば、私は7時にmondaysクラスを持っているので、毎週アラームを開始する必要があります。私は別のクラスを火曜日に持っていて、同じことをしなければなりません。ここ

はそうPD-> rqs1 = 1

Calendar cal = Calendar.getInstance(); 
     cal.setTimeInMillis(System.currentTimeMillis()); 
     cal.set(Calendar.HOUR_OF_DAY, horai); // i put the hour with the interface 
     cal.set(Calendar.MINUTE,minutoi);/// 
     cal.set(Calendar.DAY_OF_WEEK,dias.getSelectedItemPosition()+1); 
     cal.add(Calendar.SECOND, 2); 



     Intent intent = new Intent(getBaseContext(), AlarmReceiver.class); 
     intent.putExtra("name", curso); // i put the name of the curso 
     PendingIntent pendingIntent = 
       PendingIntent.getBroadcast(getBaseContext(), 
         RQS_1, intent, PendingIntent.FLAG_ONE_SHOT); 


    AlarmManager alarmManager = 
      (AlarmManager)getSystemService(Context.ALARM_SERVICE); 


    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
      cal.getTimeInMillis(), 24 * 7 * 60 * 60 * 1000 , pendingIntent);` 

を働く私のコードですが、私はそれを行う方法を探しています。 私を助けてください。おかげ

+0

は、あなたがそれを解決しましたか? –

+0

は、私はまだそれを – fer

+0

をしようとする代わりに、 'setRepeating'を使用して何が、放送再び –

答えて

0

1-本この

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
     cal.getTimeInMillis(), 24 * 7 * 60 * 60 * 1000 , pendingIntent);` 

を交換:

alarmManager.set(AlarmManager.RTC_WAKEUP, 
      cal.getTimeInMillis(), 24 * 7 * 60 * 60 * 1000 , pendingIntent); 

2-このこの

PendingIntent pendingIntent = 
      PendingIntent.getBroadcast(getBaseContext(), 
        RQS_1, intent, PendingIntent.FLAG_ONE_SHOT); 

を交換:

PendingIntent pendingIntent = 
      PendingIntent.getBroadcast(getBaseContext(), 
        RQS_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

、3-onReceive内にこれを追加します。

Intent intent = new Intent(getBaseContext(), AlarmReceiver.class); 
    intent.putExtra("name", curso); // i put the name of the curso 
    PendingIntent pendingIntent = 
      PendingIntent.getBroadcast(getBaseContext(), 
        RQS_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); 


AlarmManager alarmManager = 
     (AlarmManager)getSystemService(Context.ALARM_SERVICE); 


alarmManager.set(AlarmManager.RTC_WAKEUP, 
     cal.getTimeInMillis(), 24 * 7 * 60 * 60 * 1000 , pendingIntent);` 
0

FLAG_UPDATE_CURRENT代わりFLAG_ONE_SHOTを使用してみてください。

また、デバイスの再起動後にアラームを再スケジュールするようにしてください。 Hereが良い例です。

+0

を投稿します?????? – fer

関連する問題