Ho un servizio in esecuzione che aggiorna una notifica nella barra di notifica quando riceve un messaggio che dice che deve essere cambiato.Android - java.lang.IllegalArgumentException: contentIntent errore richiesto causato dalla notifica?
Tuttavia ho il seguente errore a volte quando la notifica deve essere aggiornata
java.lang.IllegalArgumentException: contentIntent required
Ecco il mio codice:
configurazione variabile
int icon = R.drawable.notification;
CharSequence tickerText = "Test";
long when = System.currentTimeMillis();
PendingIntent contentIntent;
Notification notification = new Notification(icon, tickerText, when);
NotificationManager mNotificationManager;
NotificationManager creazione
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
Creazione di notifica
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);
Aggiornamento della notifica
notification.icon = R.drawable.notification2;
notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent);
mNotificationManager.notify(1, notification);
Quindi qualcosa sta accadendo mia contentIntent da qualche parte lungo la linea, vorrei che essere corretto?
Viene dichiarato nella parte superiore della mia classe di servizio come variabile membro e non viene utilizzato in nessun'altra parte del codice oltre a quello mostrato sopra, quindi dove potrebbe essere reimpostato su null?
Non tutte le versioni di Android richiedono questo. Avevo un caso che funzionava bene su tutto tranne il Kindle Fire. –
Sai cosa faccio se non voglio che l'intenzione di sparare clicchi sulla notifica? Voglio solo che sia lì mentre il sistema sta facendo qualcosa e andrà avanti da solo. –
per il mio caso, mostrando notificaBar dal servizio, che sarebbe mBuilder.setContentIntent (PendingIntent.getActivity (this, 0, new Intent(), 0)); – toantran