我的闹钟和通知有问题。我设置了当地到达acerta的通知,并且没有问题。我试图让用户选择在设置中使用共享首选项获取通知的日期,并按照您在代码中看到的那样获取它们。但这不起作用,即使我决定有一天还有所有其他通知没有区别,也无法弄清楚是什么错。有人能帮我吗?谢谢大家。
我必须刷新警报吗?
SharedPreferences sharedPrefs = getSharedPreferences("SETTING_NOTIFICATION", MODE_PRIVATE);
calendar = Calendar.getInstance();
if (sharedPrefs.getBoolean("lun", true)){
calendar.set(Calendar.DAY_OF_WEEK, 0);
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 0);
notifi();
Toast.makeText(getApplicationContext(), "notification lunedi", Toast.LENGTH_LONG).show();
}
if (sharedPrefs.getBoolean("mar", true)){
calendar.set(Calendar.DAY_OF_WEEK, 1);
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 0);
notifi();
}
if (sharedPrefs.getBoolean("mer", true)){
calendar.set(Calendar.DAY_OF_WEEK, 2);
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 0);
notifi();
}
if (sharedPrefs.getBoolean("gio", true)){
calendar.set(Calendar.DAY_OF_WEEK, 3);
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 0);
notifi();
}
if (sharedPrefs.getBoolean("ven", true)){
calendar.set(Calendar.DAY_OF_WEEK, 4);
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 0);
notifi();
}
if (sharedPrefs.getBoolean("sab", true)){
calendar.set(Calendar.DAY_OF_WEEK, 5);
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 0);
notifi();
}
if (sharedPrefs.getBoolean("dom", true)){
calendar.set(Calendar.DAY_OF_WEEK, 6);
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 0);
notifi();
}
}
public void notifi(){
Intent intent1 = new Intent(Home.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Home.this, 0,intent1, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) Home.this.getSystemService(Home.this.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}