2016-12-31 53 views
0

當用戶點擊我的通知時,如何啓動活動?我試圖插入一個意圖,但它沒有做任何東西 -通知發起活動

// **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); 

回答

1

不要使用Notification.Builder,使用NotificationCompat.Builder代替。

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

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

然後在你的建設者:

mBuilder.setContentIntent(pendingIntent); 
+0

確實對所有API級別 –

+0

是的,它應該這項工作。 – GVillani82