Есть простое приложение напоминалка, всё работает нормально, только как сделать что бы уведомления были ежедневными?
Класс отвечающий за уведомления
public class AlertReceiver extends BroadcastReceiver {
private static final String TAG = "AlertReceiver";
@Override
public void onReceive(Context mContext, Intent intent) {
String Title = intent.getStringExtra(Constants.title);
long id = intent.getLongExtra(Constants.title, -1);
String content = intent.getStringExtra(Constants.title);
String channelId = mContext.getResources().getString(R.string.channel_id);
CharSequence name = mContext.getResources().getString(R.string.channel_name);
String description = mContext.getResources().getString(R.string.channel_description);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext.getApplicationContext(), channelId);
Intent ii = new Intent(mContext.getApplicationContext(), MainActivity.class);
ii.putExtra(Constants.title, id);
Log.e(TAG, "onReceive: "+id );
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, ii, 0);
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(content);
bigText.setBigContentTitle(Title);
bigText.setSummaryText(content);
mBuilder.setContentIntent(pendingIntent);
mBuilder.setSmallIcon(R.drawable.ic_fav);
mBuilder.setContentTitle(Title);
mBuilder.setContentText(content);
mBuilder.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + mContext.getPackageName() + "/raw/alarm_gentle"));
Log.e("jmbjgjg", "onReceive: " +Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + mContext.getPackageName() + "/raw/alarm_gentle").toString() );
mBuilder.setColor(Color.RED);
mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setStyle(bigText);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mChannel = new NotificationChannel(channelId, name, NotificationManager.IMPORTANCE_HIGH);
mChannel.setLightColor(Color.RED);
mChannel.enableLights(true);
mChannel.setShowBadge(true);
mChannel.setDescription(description);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
mChannel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + mContext.getPackageName() + "/raw/alarm_gentle"), audioAttributes);
if (mNotificationManager != null) {
mNotificationManager.createNotificationChannel( mChannel );
}
}
assert mNotificationManager != null;
mNotificationManager.notify(1, mBuilder.build());
}
}
Добавление заметки
public void addReminder(int startYear, int startMonth, int startDay,
int startHour, int startMinute, String title, String note, long
id){
Calendar calender = Calendar.getInstance(Locale.getDefault());
calender.clear();
calender.set(Calendar.MONTH, startMonth);
calender.set(Calendar.DAY_OF_MONTH, startDay);
calender.set(Calendar.YEAR, startYear);
calender.set(Calendar.HOUR, startHour);
calender.set(Calendar.MINUTE, startMinute);
calender.set(Calendar.SECOND, 0);
AlarmManager alarmMgr = (AlarmManager) requireActivity().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(requireContext(), AlertReceiver.class);
intent.putExtra(Constants.title, title);
intent.putExtra(Constants.description, note);
intent.putExtra(Constants.id, id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(requireActivity(), 0, intent, FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
alarmMgr.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendingIntent);
}else {
alarmMgr.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendingIntent);
}
Log.e(TAG, "addReminder: jhyhghgghghghf \n"+id + "\n" );
}