我有一个public class AlarmReceiver extends BroadcastReceiver
和一个活动,其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);
}
因此,我的onReceive
的{{1}}方法应在执行此代码后的5秒内调用,不应该吗?但事实并非如此,我已经等了几分钟但没有任何反应。是的,我已将AlarmReceiver
添加到我的清单中。
(我的手机执行<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
)