我有Android應用程序,並試圖收到推送通知。 我的問題,當點擊保留的通知打開主要活動, 我需要收到來自firebase的推送通知直接打開特定的活動。這是我的代碼打開特定的活動時,e從火力點推送通知
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.app_logo_a)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getNotification().getBody());
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
} catch (Exception e) {
Log.e("Mo", "Exception: " + e.getMessage());
}
Intent resultIntent = new Intent(getApplicationContext(), Notification_Page.class);
startActivity(resultIntent);
}
private void handleDataMessage(JSONObject json) {
if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
// app is in foreground, broadcast the push message
Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION);
pushNotification.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
notificationUtils.playNotificationSound();
Intent resultIntent = new Intent(getApplicationContext(), Notification_Page.class);
startActivity(resultIntent);
} else {
Intent resultIntent = new Intent(getApplicationContext(), Notification_Page.class);
startActivity(resultIntent);
}
}
檢查這one .. https://stackoverflow.com/questions/40718155/open-specific-activity-when-notification-clicked-in-fcm –
您是否嘗試在您收到推送通知時或用戶「點擊「UI中的通知? – Pelocho