2016-12-31 41 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