2016-10-13 152 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

否則可以發佈代碼 –