Ginso
Ginso

Reputation: 569

BroadcastReceiver does not trigger

i have a public class AlarmReceiver extends BroadcastReceiver and an Activity with the following part in its onCreate

    Intent intent = new Intent(this, AlarmReceiver.class);
    pintent = PendingIntent.getBroadcast(this, 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        alarm.setExact(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis() + 5000, pintent);
    } else {
        alarm.set(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis()+5000, pintent);
    }

So, the onReceive method of my AlarmReceivershould be called 5seconds after this code is executed, shouldn't it? But it isn't, i've waited a few minutes but nothing happens. And yes i have added <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/> to my manifest. (My phone executes setExact)

Upvotes: 2

Views: 657

Answers (1)

William Ku
William Ku

Reputation: 798

the easiest way to make sure that you have created a broadcastreceiver properly is to to add it through the context menu. In that way, the receiver will also be added to the manifest accordingly.

Adding a new broadcastreceiver Adding a new broadcastreceiver#2

Upvotes: 1

Related Questions