Ich habe einen Dienst ausgeführt, der eine Benachrichtigung in der Benachrichtigungsleiste aktualisiert, wenn er eine Nachricht erhält, die besagt, dass er geändert werden muss.Android - java.lang.IllegalArgumentException: contentIntent erforderlich Fehler durch Benachrichtigung verursacht?
Allerdings bekomme ich folgende Fehler manchmal, wenn die Benachrichtigung aktualisiert werden
istjava.lang.IllegalArgumentException: contentIntent required
Hier ist mein Code:
Variable Setup
int icon = R.drawable.notification;
CharSequence tickerText = "Test";
long when = System.currentTimeMillis();
PendingIntent contentIntent;
Notification notification = new Notification(icon, tickerText, when);
NotificationManager mNotificationManager;
NotificationManager Schaffung
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
Mitteilung Creation
Intent notificationIntent = new Intent(this, TestsApp.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.icon = R.drawable.notification3;
notification.setLatestEventInfo(this, "Registering", "Test", contentIntent);
mNotificationManager.notify(1, notification);
Update der Mitteilung
notification.icon = R.drawable.notification2;
notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent);
mNotificationManager.notify(1, notification);
So etwas meinen contentIntent irgendwo entlang der Strecke passiert, wäre das richtig sein?
Es wird am Anfang meiner Service-Klasse als Member-Variable deklariert und wird nicht anderswo im Code verwendet als oben gezeigt, also wo könnte es auf Null zurückgesetzt werden?
Nicht alle Versionen von Android erfordern dies. Ich hatte einen Fall, der mit allem außer dem Kindle Fire gut funktionierte. –
Wissen Sie, was ich mache, wenn ich beim Klicken auf die Benachrichtigung keine Absicht haben möchte? Ich will nur, dass es da ist, während das System etwas macht und es selbständig wird. –
für meinen Fall, zeigt notificationBar von Service, das wäre mBuilder.setContentIntent (PendingIntent.getActivity (this, 0, neue Intent(), 0)); – toantran