问题描述
我的通知会很好地触发,但是我的问题是,当我在通知中心中单击通知时,它无法启动我的活动,该活动已为应用程序打开.
基本上,单击我的通知后,其打开的Mainactivity,但是我想从我的应用程序中打开其他页面.
当我的应用程序位于前台并且通知到达其打开的完美页面时,但是当应用程序不在前台时则打开了Mainactivity
所以请告诉我该怎么办..?
private void sendNotification(String body) {
if (body.equals("Image Upload Successfully")){
intent= new Intent(this, Image_Gallery.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Video Upload Successfully")){
intent = new Intent(this, Video_Gallary.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Home Work Are Uploaded")){
intent = new Intent(this, HomeWork.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Daily Work Are Uploaded")){
intent = new Intent(this, DailyDairy.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Upcomming Holiday")){
intent = new Intent(this, Events.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("New Event Are Uploaded")){
intent = new Intent(this, Events.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, not_nu, intent, PendingIntent.FLAG_ONE_SHOT);
//Set sound of notification
Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Notificaton")
.setContentText(body)
.setAutoCancel(true)
.setVibrate(v)
.setSound(notificationSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(not_nu , notifiBuilder.build());
}
在通知有效负载中,您需要click_action
属性,以便单击通知.
请检查此.
此外,在定义click_action
属性时,还需要在要启动的活动的<intent-filter>
中相应的<action>
属性.
此视频对其进行了非常详细的说明.
不过,请注意,如果要从Firebase控制台发送通知,则不能设置click__action
属性.仅当您从自己的管理服务器或使用Firebase Cloud Functions发送通知时,您才能这样做.
最后,在启动的活动中,您可以使用getIntent()
获取其余的通知数据.查看此答案以获取有关如何执行此操作的更多详细信息.
My notifications fires very well, but my problem is that, when I click on notification in Notification Center, it does not start my Activity which one is open for app.
Basically, after clicking on my notification its open Mainactivity but i want to open some another pages from my application.
when my app is in foreground and notification arrived its open perfect page but when application is not in foreground it's open Mainactivity
so please tell me what should i can do for that..?
private void sendNotification(String body) {
if (body.equals("Image Upload Successfully")){
intent= new Intent(this, Image_Gallery.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Video Upload Successfully")){
intent = new Intent(this, Video_Gallary.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Home Work Are Uploaded")){
intent = new Intent(this, HomeWork.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Daily Work Are Uploaded")){
intent = new Intent(this, DailyDairy.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Upcomming Holiday")){
intent = new Intent(this, Events.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("New Event Are Uploaded")){
intent = new Intent(this, Events.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, not_nu, intent, PendingIntent.FLAG_ONE_SHOT);
//Set sound of notification
Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Notificaton")
.setContentText(body)
.setAutoCancel(true)
.setVibrate(v)
.setSound(notificationSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(not_nu , notifiBuilder.build());
}
In your notification payload, you need the click_action
attribute for the notification to be clickable.
Please check this section of the Firebase docs.
Also, when you define the click_action
attribute, you will also need a corresponding <action>
attribute in the <intent-filter>
of the activity that you wish to launch.
This video explains it in quite a detailed manner.
Though, please note that you can not set the click__action
attribute if you're sending notifications from the Firebase Console. You can only do so if you send a notification from your own Admin server or using Firebase Cloud Functions.
Lastly, in the activity that is launched, you can obtain the rest of the notification data using getIntent()
. Check out this answer for more details on how to do that.
这篇关于活动通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!