2017-04-03 10 views
1

私はこのトピックについて多くの質問がありますが、私がやろうとしていることについては何も助けてくれないので、助けてくれることを願っています。 時刻の異なる時刻にトリガする3つのアラームを設定したい場合は、午前9時、午後1時、午後6時に対応します。時間に関する情報はsqliteデータベースに保存されます。3種類のアラームを設定してください

私はデータベースを行単位で読み取り、1時間ごとにアラームを設定しました。 idのために私はちょうど番号を使用しています。

これは私が使用しているコードです。 1つのアラームを設定すると機能しますが、さらに設定しようとすると、どれも設定されません。

private void setAlarm() throws ParseException { 
     DBHelper helper = new DBHelper(Main3Activity.this); 
     Cursor cursor = helper.getQueryDB(); 
     cursor.moveToPosition(-1); 
     int i = 1; 

     AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
     Intent intent = new Intent(getBaseContext(), AlarmReceiver.class); 

     while (cursor.moveToNext()) { 
      final String name = cursor.getString(1); 
      final String time = cursor.getString(2); 

      PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), i, intent, 0); 

      Calendar t = parseTime(time); 

      alarmManager.set(AlarmManager.RTC_WAKEUP, t.getTimeInMillis(), pendingIntent); 


      i++; 
     } 
} 
public Calendar parseTime (String t) throws ParseException { 
     SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy"); 
     Calendar cal = Calendar.getInstance(); 
     cal.setTime(sdf.parse(t)); 
     return cal; 
} 

答えて

0

コードは問題なく、受信機をAndroidマニフェストに置くのを忘れていました。 私の悪い!

1

アラームを1つ設定するだけで、次のアラームが設定されます。

+0

あなたの答えはさらに発展させることができますか?私はあなたが何を意味するのか完全に理解していません。 – cotita

関連する問題