本文介绍了为什么我的闹钟没有响起? (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的闹钟在特定时间或根本没有响(我尝试将其设置为当前时间的一分钟).我已确保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);
更多推荐
为什么我的闹钟没有响起? (安卓)
发布评论