这是我的通知代码,点击后会默认打开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 :(得分:0)
试试这段代码:
Intent intent = new Intent(this, SecondActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(c, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
并在setContentIntent()中传递pendingIntent而不是PendingIntent.getActivity(this,0,getIntent(), PendingIntent.FLAG_UPDATE_CURRENT