[英]Alarm is not Fired when i set time in android
public class SchedulerSetupReceiver extends WakefulBroadcastReceiver {
private static final String APP_TAG = "com.hascode.android";
private static final int EXEC_INTERVAL = 10 * 1000;
DBhelper dbhelper;
@Override
public void onReceive(final Context ctx, Intent intent) {
Log.d(APP_TAG, "SchedulerSetupReceiver.onReceive() called");
dbhelper = new DBhelper(ctx);
String[] ID = dbhelper.FetchAllID();
String[] time = dbhelper.FetchAlltime();
ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
AlarmManager alarmManager = (AlarmManager) ctx
.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.HOUR_OF_DAY, 16);
calendar.set(calendar.MINUTE, 22);
calendar.set(calendar.SECOND, 0);
calendar.set(calendar.MILLISECOND, 0);
long sdl = calendar.getTimeInMillis();
for (int k = 0; k < ID.length; k++) {
intent = new Intent(ctx, SchedulerEventReceiver.class);
// Loop counter `i` is used as a `requestCode`
PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, k,
intent, 0);
// Single alarms in 1, 2, ..., 10 minutes (in `i` minutes)
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, sdl,
pendingIntent);
intentArray.add(pendingIntent);
}
}
这是我的警报代码,我想为特定时间设置警报,但是在完成时间时不会触发,我已经使用日历,并且我已设置为4:20分钟Pm,因为我在第16小时和第20分钟添加了时间,但是设备时间达到4.20 Pm时未触发,请告诉我我在做什么错误
尝试这个
alarmManager.set(AlarmManager.RTC_WAKEUP, sdl,
pendingIntent);
确保已在清单中注册了广播接收器。
<receiver android:name=".SchedulerEventReceiver"/>
并提供警报许可。
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
我想您忘了告诉日历今天是星期几。
calendar.setTimeInMillis(System.currentTimeMillis());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.