AndroidStudio中AlarmScheduler不能工作/无法设置闹钟
创始人
2024-08-20 13:30:09
0
  1. 确认是否已经请求了必要的权限(如 RECEIVE_BOOT_COMPLETED、SET_ALARM 等)。
  2. 确认 AlarmScheduler 是否在正确的时间和日期设置了闹钟。
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);

Intent alarmIntent = new Intent(context, MyAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (alarmManager != null) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    } else {
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    }
}
  1. 如果上述解决方法都无效,请检查设备的省电模式或第三方应用程序是否阻止应用程序提醒或闹钟。在某些品牌和型号的设备上,电池优化和省电模式可能会影响闹钟的工作。如果是这种情况,请在设置中禁用省电模式或电池优化,或将应用程序添加到白名单中。

相关内容

热门资讯

盘点一款!wepower德州设... 盘点一款!wepower德州设置,governorofpoker3有挂,详细教程(有挂介绍)-哔哩哔...
透明挂透视!(wePOke)软... 透明挂透视!(wePOke)软件透明挂,扑克王辅助工具,详细教程(有挂规律)-哔哩哔哩;wePOke...
玩家必看分享!(wepOkE)... 《wepOkE软件透明挂》是一款多人竞技的wepOkE辅助透视游戏,你将微扑克对手来到同一个战场,为...
专业讨论!德州扑克ai机器人,... 《专业讨论!德州扑克ai机器人,(wepOkE)软件透明挂,详细教程(有挂透明)-哔哩哔哩》 德州扑...
透视ai代打!德州ai辅助神器... 透视ai代打!德州ai辅助神器下载,pokermaster有外挂,详细教程(有挂技巧)-哔哩哔哩;玩...
玩家必看教程!poker有外挂... 玩家必看教程!poker有外挂,aa poker有外挂,详细教程(有挂规律)-哔哩哔哩;人气非常高,...
透明辅助!(wePOke)软件... 此外,数据分析德州(wePOke)辅助神器app还具备辅助透视行为开挂功能,通过对客户wePOke透...
总算了解!线上wpk到底有外挂... 总算了解!线上wpk到底有外挂,鱼扑克app ai,详细教程(有挂规律)-哔哩哔哩1、点击下载安装,...
必备攻略!轰趴大菠萝十三水有外... 必备攻略!轰趴大菠萝十三水有外挂,(wepoke)软件透明挂,详细教程(有挂介绍)-哔哩哔哩;原来确...
2024教程!(wepOke)... 2024教程!(wepOke)软件透明挂,wepower有辅助器,详细教程(有挂教学)-哔哩哔哩准备...