FirebaseMessagingService 11.6.0 HandleIntent
losFirebaseMessagingService
tiene el métodoonMessageReceived()
que deberíamosoverride
manejarnotifications
, pero esto solo funciona cuando la aplicación está enForeground
.
Manejarnotifications
incluso cuando la aplicación está en segundo plano, solía anular elhandleIntent
, simplemente llamar alonMessageReceived()
.
EnFirebaseMessagingService
11.6.0, el métodohandleIntent
se convirtió en final, con eso dicho, no puedo anularlo como lo estaba haciendo.
¿Cómo debo manejar las notificaciones cuando mi aplicación está en segundo plano en la versión 11.6.0?
public class NotificationsListenerService extends FirebaseMessagingService {
private static final String TAG = "NotificationsListenerService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
String notifyData = remoteMessage.getData().get("notifData");
if(notifyData.contains("|")){
String[] itens = notifyData.split("\\|");
notifyData = itens[0];
}
String notifyType = remoteMessage.getData().get("notifType");
String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("body");
if(!isAppInForeground(App.getContext())){
sendNotification(title, message, notifyData, notifyType);
}
}
@Override
public final void handleIntent(Intent intent) {
...
this.onMessageReceived(builder.build());
...
}
private void sendNotification(String messageTitle, String messageBody, String notifyData, String notifyType) {
...
}
//Detect if app is in foreground
private boolean isAppInForeground(Context context) {
...
}
}