Я пытаюсь установить Alarm 8am каждый день для выполнения mainActivity, так что это моя MainActivity:
protected void onCreate(Bundle savedInstanceState){
Intent Alarm = new Intent(MainActivity.this,LongRunningService.class);
startService(Alarm);
}
LongRunningService - Сервис:
AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 00);
Intent i = new Intent(this,AlarmReceiver.class);
intent.setAction("startAlarm");
PendingIntent pi = PendingIntent.getBroadcast(this,0,i,0);
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pi);
AlarmReceiver. java
public void onReceive(Context context, Intent intent){
if ("startAlarm".equals(intent.getAction()))
Log.d(TAG, "onReceive! "); //not working?
}
Log.d(TAG, "onReceive! "); //it's working