Reputation: 569
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 AlarmReceiver
should 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
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.
Upvotes: 1