Gelöst, danke an alle, die beigetragen haben.Benachrichtigung wird nach einigen Sekunden nicht gelöscht. -Android
Dies ist meine Funktion, mit der ich die Benachrichtigung für den Benutzer anzeigen kann. Aus irgendeinem Grund sieht es jedoch so aus, als ob die Benachrichtigungen nicht mehr gelöscht werden ... nicht sicher warum. Beachten Sie die Variable MELDUNG initialisiert als:
public static int NOTIFICATION = 1;
public void displayNotification(String title, String message, Intent intent) {
PendingIntent resultPendingIntent = PendingIntent.getActivity(mCtx, NOTIFICATION,
intent, PendingIntent.FLAG_UPDATE_CURRENT); //FLAG_ONE_SHOT ? FLAG_UPDATE_CURRRENT
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
Notification notification;
notification = mBuilder.setSmallIcon(R.mipmap.ic_logo_nobg).setTicker(title).setWhen(0)
.setContentIntent(resultPendingIntent)
.setContentTitle(title)
.setSmallIcon(R.mipmap.ic_logo_nobg)
.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_roundedlogo))
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setDefaults(Notification.DEFAULT_ALL)
.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
final NotificationManager notificationManager = (NotificationManager) mCtx
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION, notification);
// This method will get rid of the notification AND the message after 1 day
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
notificationManager.cancel(NOTIFICATION);
Preference_Manager.getInstance(mCtx).deleteKeyMessage(NOTIFICATION);
// Preference_Manager.getInstance(mCtx).deleteKeyMessageid(NOTIFICATION);
}
}, 5000/*howMany */);
}
});
NOTIFICATION++;
}
Siehe Ich verwende lokale endgültige Variable für Benachrichtigungs-ID –
Dies funktionierte perfekt, danke. – dfabiano