2016-12-31 32 views
0

Wie starte ich eine Aktivität, wenn der Benutzer auf meine Benachrichtigung klickt? Ich habe versucht, eine Absicht eingefügt, aber es ist nicht anything-Benachrichtigung starten eine Aktivität starten

// **non cleareble notification**// 
    NotificationManager notificationManager = (NotificationManager) this 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification noti = new Notification.Builder(this) 
      .setAutoCancel(false) 
      .setContentIntent(
        PendingIntent.getActivity(this, 0, getIntent(), 
          PendingIntent.FLAG_UPDATE_CURRENT)) 
      .setContentTitle("HELLO world") 
      .setContentText("PLEASE CHECK WE HAVE UPDATED NEWS") 
      .setDefaults(Notification.DEFAULT_ALL).setOngoing(true) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setTicker("ticker message") 
      .setWhen(System.currentTimeMillis()).build(); 
    noti.flags |= Notification.FLAG_NO_CLEAR; 
    notificationManager.notify(0, noti); 
    Intent intent = new Intent(this, NotificationAction.class); 

Antwort

1

tun nicht Notification.Builder Verwenden Sie verwenden NotificationCompat.Builder statt.

Intent intent = new Intent(this, NewActivity.class); 

PendingIntent pendingIntent = 
    PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

Und dann in Ihrem Erbauer:

mBuilder.setContentIntent(pendingIntent); 
+0

funktionierts auf allen Ebenen api –

+0

Ja, es sollte. – GVillani82

Verwandte Themen