Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: why doesn't AlarmManager work?

I have the following code. which is supposed to send a message in logcat at an interval but is not working. There are a lot of similar posts on stackoverflow but I am not able to figure out the problem. Is there a brainiac somewhere that can help me?

<receiver android:name="BoopoohooAlarmReceiver"></receiver>

public void startAlarmManager(long interval){
    Context context = getApplicationContext();
    Intent intent = new Intent(context, BoopoohooAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 10);
    Log.i(DEBUG, "hollaa");
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, pendingIntent);
}

public class BoopoohooAlarmReceiver extends BroadcastReceiver {
    private final String DEBUG = "BoopoohooAlarmReceiver"; 
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(DEBUG, "onReceive");
    }
}

Thanks.

like image 555
djcharon Avatar asked Apr 06 '26 16:04

djcharon


1 Answers

Try to add the "." (point) in front of receiver name in the android manifest file declaration.

<receiver android:name=".BoopoohooAlarmReceiver"></receiver>

This may help too.

like image 151
Andy Res Avatar answered Apr 09 '26 09:04

Andy Res



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!