I tried a lot to make this work, but I can't figure out what's wrong. If I call sendBroadcast(new Intent(ACTION))
, my broadcast receiver gets called, but it's not working with the AlarmManager:
@EReceiver
public class MyBroadcastReceiver extends AbstractBroadcastReceiver {
public static final int REQUEST_CODE = 12345;
public static final String ACTION = "com.xxx.yyy.alarm";
public static void setAlarm(Context context) {
Log.e("AUTOMATIC", "setAlarm");
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MyBroadcastReceiver.class);
intent.setAction(ACTION);
PendingIntent pIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 5000, pIntent);
}
@ReceiverAction(ACTION)
public void init(Context context) {
Log.e("BROADCAST", "woke up receiver action");
MyService_.intent(context).run().start();
}
}
The problem is that you are using the original class in the intent, not the generated one. Change to this:
Intent intent = new Intent(context, MyBroadcastReceiver_.class);
Note the underscore in the class name.