gpt4 book ai didi

android - 如何查看闹钟是否设置

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:57 25 4
gpt4 key购买 nike

我正在尝试检查我的闹钟是否处于 Activity 状态。 alarmIsSet 方法在设置闹钟前会返回false,在设置闹钟时返回true。到目前为止一切顺利,但是,在我取消警报后,alarmIsSet 将继续返回 true,直到我重新启动设备。我该如何解决这个问题?

public class Alarm extends Activity {
private Intent intent = new Intent("PROPOSE_A_TOAST");

private void alarm (boolean activate) {
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, 0);

if(activate == true) {
int type = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long interval = 3000;
long triggerTime = SystemClock.elapsedRealtime();
am.setRepeating(type, triggerTime, interval, pi);
} else {
am.cancel(pi);
}
}

private boolean alarmIsSet() {
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_NO_CREATE) != null;
}
}

最佳答案

你只需要添加

pi.cancel();

之后

am.cancel(pi);

关于android - 如何查看闹钟是否设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4713592/

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