2016-10-13 146 views
0

我设法从PHP文件发送通知消息并使用Firebase云消息传递(FCM)发送到手机。打开新的活动通知点击

一旦用户点击移动托盘上的通知消息,我如何重定向到具有相同消息以及时间和日期的另一个布局?

回答

0

请参阅下面的代码。我正在使用它,它正在打开我的HomeActivity。

NotificationManager notificationManager = (NotificationManager) context 
     .getSystemService(Context.NOTIFICATION_SERVICE); 
Notification notification = new Notification(icon, message, when); 

Intent notificationIntent = new Intent(context, HomeActivity.class); 

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
     | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

PendingIntent intent = PendingIntent.getActivity(context, 0, 
     notificationIntent, 0); 

notification.setLatestEventInfo(context, title, message, intent); 
notification.flags |= Notification.FLAG_AUTO_CANCEL; 
notificationManager.notify(0, notification); 
+0

感谢您的帮助,顺便说一句,在哪里把该代码..?实际上,我使用Android工作室 – Ksr

+0

创建了多个PendingIntent对象,其Intents只在其“额外”内容中有所不同,期望每次都获得不同的PendingIntent。 –

+0

否则可以发布代码 –