0
我在我的應用程序中創建了兩個後臺服務。我必須在一段時間內開始我的後勤服務。所以我正在用這個鬧鐘。一項服務必須每15分鐘啓動一次,另一項服務每天啓動一次。我的代碼在這裏。如何設置時間重複鬧鐘爲Android的每15個薄荷糖?
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 15);
Intent intent = new Intent(this, TestService.class);
pintent = PendingIntent.getService(this, 0, intent, 0);
alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);;
i=15;
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), i*1000, pintent);
if (networkInfo != null && networkInfo.isConnected())
{
startService(new Intent(getBaseContext(), TestService.class));
}
else
{
}
我用這樣。它的作品第一次精細。這意味着我的警報在第一次使用15次薄荷糖後再次開始。然後每15秒重複一次。我不知道如何正確設置時間。任何機構都可以告訴我實現這個目標嗎?提前致謝。
時,接收器15分鐘後 – appukrb
檢測報警設置新的報警請參閱本http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/ – appukrb
你正在使用15 * 1000 = 15000毫秒= 15秒時間間隔,將其更新爲15 * 60 * 1000 – Kedarnath