0
我確定這是簡單的事情,但我沒有搞清楚,我試圖做出一個簡單的重複鬧鐘,它從來沒有被觸發,我擁有的是:Android鬧鐘沒有被觸發
private void setupAlarms()
{
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, RepeatingAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(HelloAndroid.this, 0, intent, 0);
GregorianCalendar fifteenSeconds = (GregorianCalendar)Calendar.getInstance();
fifteenSeconds.add(Calendar.MINUTE, 0);
fifteenSeconds.set(Calendar.SECOND, 15);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(), fifteenSeconds.getTimeInMillis(), pendingIntent);
}
這是從主要的onCreate調用稱爲
我報警接收機:
public class RepeatingAlarm extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, R.string.hello, Toast.LENGTH_SHORT).show();
}
}
在我的表現,我已經加入:
<receiver android:name=".RepeatingAlarm" android:process=":remote" />
任何幫助,非常感謝
我不確定如果fifteenSeconds.getTimeInMillis()真的返回15 * 60 * 1000 [毫秒]? – 2011-01-20 13:17:17
我認爲它沒有。您可以將日曆設置爲秒數,但毫秒值在2個相同設置時間內會有所不同。 – r1k0 2011-01-20 13:30:24