为什么我的闹钟没有响起? (安卓)

编程入门 行业动态 更新时间:2024-10-28 18:25:11
本文介绍了为什么我的闹钟没有响起? (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的闹钟在特定时间或根本没有响(我尝试将其设置为当前时间的一分钟).我已确保setAlarm()处于关闭状态,因为日志Log.d("asas", "adasd");处于关闭状态.我不知道出了什么问题,如果您知道如何解决此问题,请告诉我.谢谢

My alarm does not go off at the specific time or at all (I have tried setting it to one minute of current time). I have made sure that setAlarm() is going off because the log Log.d("asas", "adasd"); goes off. I do not know what is wrong, if you see how I can fix this please let me know. Thanks

public void setAlarm(){ AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, DrawOverAppsService.class); PendingIntent alarmIntent = PendingIntent.getActivity(MainActivity.this, 123, intent, 0); if(sp.getBoolean("startChecked",false) == true) { Log.d("asas", "adasd"); java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(java.util.Calendar.HOUR_OF_DAY, 19); alarmMgr.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent); } if(sp.getBoolean("startChecked",false) == false) { Log.d("asdasd","asdasdasd"); alarmMgr.cancel(alarmIntent); } }

推荐答案

将PendingIntent alarmIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);更改为PendingIntent alarmIntent = PendingIntent.getService(MainActivity.this, 0, intent, 0);

更多推荐

为什么我的闹钟没有响起? (安卓)

本文发布于:2023-11-27 04:55:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:闹钟

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!