[英]How do I make my notification launch an activity when clicked?
這是我的通知代碼,當單擊該代碼時,默認情況下會打開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);
試試這個代碼:
Intent intent = new Intent(this, SecondActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(c, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
並在setContentIntent()中而不是PendingIntent.getActivity(this,0,getIntent(),PendingIntent.FLAG_UPDATE_CURRENT
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.