我的问题是我想显示一个firebase
通知,该通知是单击时重定向到特定活动的。
在显示应用程序的情况下单击该按钮即可使用。
但是,当应用程序关闭并单击通知时,它仅打开MainActivity
,就像通知仅启动应用程序一样。
如何使通知打开该特定活动?
我的showNotification
方法是:
private void showNotification(String title, String content) {
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("default",
"YOUR_CHANNEL_NAME",
NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("YOUR_NOTIFICATION_CHANNEL_DISCRIPTION");
if (mNotificationManager != null)
mNotificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "default")
.setSmallIcon(R.mipmap.ic_launcher) // notification icon
.setContentTitle(title) // title for notification
.setContentText(content)// message for notification
.setSound(defaultSoundUri) // set alarm sound for notification
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(getApplicationContext(), CouponsActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pi);
if (mNotificationManager != null)
mNotificationManager.notify(0, mBuilder.build());
}