2016-08-03 7 views
0

a haben 8 Versionen des folgenden Codes ausprobiert, aber die Home-Aktivität wird nicht gestartet, wenn ich auf die Benachrichtigung klicke. HierDie Aktivität wird nicht gestartet, nachdem auf eine Benachrichtigung geklickt wurde

ist, den Code (es ist innerhalb eines Dienstes)

NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); 
builder.setSmallIcon(R.mipmap.alert); 
builder.setContentTitle(""); 
builder.setContentText("Running in Background"); 
builder.setOngoing(true); 

IntenIntenticationIntent = new Intent(getApplicationContext(), Home.class); 

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,notificationIntent, 0); 
notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE); 
notificationManager.notify(NOTIFICATION_ID, builder.build()); 

Antwort

1

Könnten Sie den Code bitte?

Intent notificationIntent = new Intent(this, Home.class); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.mipmap.alert); 
builder.setContentTitle(""); 
builder.setContentText("Running in Background"); 
builder.setOngoing(true); 
builder.setContentIntent(contentIntent); 

notificationManager = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE); 
notificationManager.notify(NOTIFICATION_ID, builder.build()); 
+0

Sie sind eine erstaunliche !! Ich habe stundenlang versucht, das zur Arbeit zu bringen. Ich denke, es war die setContentIntent, die ich vermisste. – Movieboy

Verwandte Themen