アクティビティがあります。ここに 2 つのボタンがあります。
「アラーム時刻を選択」のボタン 1。タップすると TimePicker が表示され、アラームの時間を選択します。
「アラームの設定」のボタン 2。タップするとアラームセット。
私がやっていること:
設定した目覚まし時刻に に電話しBroadcastReceiver
ます。デモでは、設定したアラームの時間と文字列のみを出力しますToast
クエリとは:
「現在の時刻を 4.00 PMのようにアラーム時刻を設定し、アラーム時刻を 6.00 PMに設定すると、アラームは常に を呼び出し、BroadcastReceiver
それはWork Fine
.
BUT
現在の時刻が午後 4 時で、アラームを午後 2 時に設定した場合BroadCastReceiver
、同時に電話がかかってきますが、このようなことはしたくありません。」
.
AlarmManager には、次のスニペットを使用します。
AlarmManager am = (AlarmManager) getSystemService(SetAlarm.ALARM_SERVICE);
Intent intent1 = new Intent(SetAlarm.this, BroadCast.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(SetAlarm.this, 0,intent1,PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);