gpt4 book ai didi

android - 警报管理器从未在 android 中触发

转载 作者:行者123 更新时间:2023-11-29 17:52:08 25 4
gpt4 key购买 nike

这段代码有什么问题?我试图在上午 11 点触发警报,我将其设置为上午 10 点,因此它应该在一个小时后触发,但从未发生过

      public void schedulePayment(Context ctxt,int numOfDays) {

mgr = (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
Intent myIntent = new Intent(ctxt, NotificationPayment.class);
PendingIntent pendingIntent = PendingIntent.getService(ctxt, 0, myIntent, 0);

Calendar time = Calendar.getInstance();

time.setTimeInMillis(System.currentTimeMillis());
time.clear();

time.set(Calendar.HOUR_OF_DAY, 11);
time.set(Calendar.MINUTE, 1);
time.set(Calendar.SECOND, 1);

long limit_time = time.getTimeInMillis() ;

// if(time.before(Calendar.getInstance())){
// Log.d("add time ","extra");
// limit_time+=AlarmManager.INTERVAL_DAY;
// }
Log.d("in schedule ","done..."+limit_time);
mgr.setRepeating(AlarmManager.RTC_WAKEUP, limit_time,AlarmManager.INTERVAL_HALF_HOUR, pendingIntent);

}

最佳答案

不要调用 time.clear(); 这会删除所有日历字段,例如日期。

关于android - 警报管理器从未在 android 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22125734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com