So I have a BroadcastReceiver which looks like this:
public class UpdateReceiver extends BroadcastReceiver {
public UpdateReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 10);
System.out.println("Broadcast received");
PendingIntent operation = PendingIntent.getService(context, 0,new Intent("REFRESH_THAT"), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, System.currentTimeMillis(), cal.getTimeInMillis(), operation);
}
}
This is how I call the BroadcastReceiver
Intent in = new Intent ("REFRESH_BROADCAST");
sendBroadcast(in);
And this is my intent-filter in Android Manifest file
<service android:name = ".services.RefreshService">
<intent-filter>
<action android:name="REFRESH_THAT"/>
</intent-filter>
</service>
<receiver android:name=".services.UpdateReceiver">
<intent-filter>
<action android:name="REFRESH_BROADCAST"/>
</intent-filter>
</receiver>
BroadcastReceiver received a brodcast without any problem, but AlarmManager seems to do nothing. If I call operation.send() it works without a problem, so I presume there is something wrong with AlarmManager.
Alright so finally I found a solution a it was my fault.
I have set
int typetoAlarmManager.ELAPSED_REALTIMEandlong triggerAtMillistoSystem.currentTimeMillis()property ofalarmManager.setInexactRepeating(.....)which is wrong, it only can be paired withAlarmManager.RTC / RTC_WAKEUP.So the functional code is this:
I should really read API documentation more carefully. If you hover
AlarmManager.ELAPSED_REALTIME, it will told you what kind of time trigger you have to use. Hope this my stupid mistake will help someone in future.