我正在开发一个通知方法,成功了,但我怎么能实现 Onclick
如何实现Onclick方法来导航一个特定的活动?
private void notification() {
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
{
NotificationChannel channel=new NotificationChannel("n","n", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager=getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
NotificationCompat.Builder builder=new NotificationCompat.Builder(this,"n")
.setContentText("Alert")
.setSmallIcon(R.drawable.ic_notifications)
.setAutoCancel(true)
.setContentText("Check your fit Room Request");
NotificationManagerCompat managerCompat=NotificationManagerCompat.from(this);
managerCompat.notify(999,builder.build());
}
Intent intent = new Intent(this, YourActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
那么
NotificationCompat.Builder builder=new NotificationCompat.Builder(this,"n")
.setContentIntent(pendingIntent)
.....