2017-03-25 81 views
0

這是我的通知的代碼,點擊後默認打開mainactivity,但是如何更改它?點擊時我想打開SecondActivity如何讓我的通知在點擊時啓動一項活動?

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("X ADB").setContentText("client in running") 
      .setOngoing(true).setSmallIcon(R.drawable.ic_launcher) 
      .setTicker("ticker message") 
      .setWhen(System.currentTimeMillis()).build(); 
    noti.flags |= Notification.FLAG_NO_CLEAR; 
    notificationManager.notify(111, noti); 

回答

0

嘗試此代碼:

Intent intent = new Intent(this, SecondActivity.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(c, 0, intent, 
      PendingIntent.FLAG_ONE_SHOT); 

而在setContentIntent(合格的PendingIntent)代替PendingIntent.getActivity(此,0,getIntent(), PendingIntent.FLAG_UPDATE_CURRENT