Я должен управлять набором уведомлений, как показано на этом изображении (не говоря уже о дубликатах):
![notifications](https://i.stack.imgur.com/kKiJZ.png)
Я должен отправить уведомление для каждого элемента, управляя удалением уведомления (чтобы приложение не отправляло уведомление), а также когда изменяется «уведомление» (дата и время).
Как я могу управлять всем этим, даже если приложение находится в фоновом режиме / спит?
Это мой метод в CoreActivity.java:
public void notifyPush(Date datetime)
{
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
//Intent intent = new Intent(context,NotificationReceiver.class);
//PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
//nuovo codice
Intent intent = new Intent(CoreActivity.this , NotificationReceiver.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(CoreActivity.this, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent); //set repeating every 24 hours
//fine nuovo codice
Notification notification = new Notification.Builder(context)
.setSound(soundUri)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Notifica")
.setContentText("Abbiamo le notifiche").
addAction(R.drawable.ic_launcher_foreground, "Open", pendingIntent)
.addAction(0, "Remind", pendingIntent).build();
NotificationManager notifManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notifManager.notify(0, notification);
}
NotificationReceiver.java
package com.example.msnma.movienotifier.notify;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
import com.example.msnma.movienotifier.R;
public class NotificationReceiver extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_core);
TextView tv = new TextView(this);
tv.setText("Notification Text");
setContentView(tv);
}
}