为什么我的警报没有响? (机器人)

时间:2017-07-01 02:52:27

标签: android alarmmanager

我的闹钟在特定时间或根本没有响应(我已尝试将其设置为当前时间的一分钟)。我确保setAlarm()因为日志Log.d("asas", "adasd");关闭而关闭。我不知道有什么问题,如果你知道我怎么解决这个问题,请告诉我。感谢

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);
    }
}

1 个答案:

答案 0 :(得分:0)

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