Actualmente estoy tratando de crear una app con la que puedes enviar una notificación de inserción a otro dispositivo.
Me han desplegado las funciones a firebase (el nodeJS index.js archivo) y siempre que puedo crear una notificación, se envía con el tema de "notificaciones" en la base avanzada. La secuencia de comandos se activa como puedo ver en los registros. Así que todo va bien.
El problema que me estoy quedando en el hecho de que cuando me suscribo a este tema y enviar una notificación desde el otro dispositivo es muy inestable. A veces me recibirlo inmediatamente, y muchas veces se necesita un tiempo muy largo (unos 5 minutos) para recibir.
Aquí está mi actual archivo Java que deben manejar las notificaciones entrantes:
package nl.c99.notificationtestingapp;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class FCMService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
/* There are two types of messages data messages and notification messages. Data messages are handled here in onMessageReceived whether the app is in the foreground or background. Data messages are the type traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app is in the foreground. When the app is in the background an automatically generated notification is displayed. */
String notificationTitle = null, notificationBody = null;
String dataTitle = null, dataMessage = null;
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData().get("message"));
dataTitle = remoteMessage.getData().get("title");
dataMessage = remoteMessage.getData().get("message");
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
notificationTitle = remoteMessage.getNotification().getTitle();
notificationBody = remoteMessage.getNotification().getBody();
}
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
sendNotification(notificationTitle, notificationBody, dataTitle, dataMessage);
}
}
¿Qué estoy haciendo mal, es el problema de mi lado?