我已经多次使用警报,但我一生都无法触发它......我做错了什么?我试过触发服务,广播接收器,一切。我尝试过从更早的时间和将来(从现在起 5 秒)触发它。据我所知,它正在被设置,它没有抛出错误,我的日志正在触发......但 AlarmReceiver 中没有任何内容被触发。
public void setAlarm() {
Calendar exp = Calendar.getInstance();
exp.set(Calendar.SECOND, 5);
AlarmManager am = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, exp.getTimeInMillis(), PendingIntent.getService(mContext, 0, new Intent(mContext, AlarmReceiver.class), 0));
Log.i("", "Alarm set for " + DateFormat.format("MMMM dd, yyyy hh:mma", exp.getTime()));
}
}
public class AlarmReceiver extends Service {
@Override
public IBinder onBind(Intent intent) {
Log.d("", "onBind Tiggered");
return null;
}
public void onCreate() {
Log.d("", "onCreate Triggered");
}
}