0

新しい時間ごとに開始時にのみ受信者に電話することは可能ですか? サービスを実行していて、時間が変わったときだけレシーバーに電話する必要があります。たとえば、5 時から 6 時などですか? どうすればそれを行うことができますか?

4

2 に答える 2

1

を使用する必要がありますAlarmManager。次に、通知する時間をスケジュールします。他の例については、Google で検索してください。

アップデート:

あなたができることは、時間が 7.30 の場合は 8.00 で、次の時間に目を覚ますことです。次に、次回の開始時に 1 時間ごとに起床するようにスケジュールします。

  Calendar c = Calendar.getInstance(); 
            c.set(Calendar.HOUR,c.get(Calendar.HOUR)+1);
            c.getTimeInMillis(); // use this in alarmmanager for the first time, 60*60*1000 from next time
于 2012-04-14T17:41:28.593 に答える
0

これには、GregorianCalendar と AlarmManager の組み合わせを使用できます。基本的に、現在の時刻に 1 時間を加算し、最も近い時間に切り捨てます。ここで例を見てください:

long UPDATE_INTERVAL = 60 * 60 * 1000; // 1 hour in milliseconds.

Calendar c = new GregorianCalendar(); // Get current time
c.add(Calendar.HOUR_OF_DAY, 1); // Add one hour to the current time.

// Set minutes, second, millisecond to 0, such that we ensure that an update is done
// at the end of the hour.
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);

final AlarmManager alarm = (AlarmManager) context.getSystemService(ALARM_SERVICE);

// Set an alarm, starting from the end of the current hour, every hour, to execute
// the update service.
// pIntent is the pending intent you would like activate.
alarm.setRepeating(AlarmManager.RTC, c.getTimeInMillis(), UPDATE_INTERVAL, pIntent);

受話器を呼び出す方法を知っていると思います。

于 2012-04-14T17:48:39.087 に答える