Reputation: 5830
Firebase Server sends notification, I get it, but my MyFirebaseMessagingService's onMessageReceived is not being called.
This is MyFirebaseMessagingService:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static String id;
private static PSTrip trip;
public void onMessageReceived(final RemoteMessage message) {
Log.i("", "MyFirebaseMessagingService onMessageReceived");
final Map data = message.getData();
FcmService.triggerSmoochNotification(data, this);
final Map bundle = data;
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Log.i("", "GLOBAL intances before GCM:" + Realm.getGlobalInstanceCount(PSApplicationClass.Config));
final Realm realm = Realm.getInstance(PSApplicationClass.Config);
try {
final RealmResults < PSTrip > completed = realm.where(PSTrip.class).equalTo("status", "active").findAll();
if (completed != null && completed.size() > 0) {
id = new String(completed.get(0).getId());
trip = new PSTrip(completed.get(0));
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
completed.deleteAllFromRealm();
}
});
}
generateNotificationStandard(MyFirebaseMessagingService.this, data.get("title"), message, null, null, false, false);
} catch (Exception e) {
Utils.appendLog("GCMIntentService onMessageReceived error: " + e.getMessage(), "E", Constants.PUSH_NOTIFICATIONS);
}
realm.close();
}
});
}
}
I am using this version of firebase:
implementation 'com.google.firebase:firebase-messaging:12.0.1'
And I have my FirebaseMessagingService declared in my AndroidManifest like this:
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Somehow my notifications are shown, but my method is not being called. How can I make it so my messages are received and handled through this?
Also: the server uses this to send the data. Might this be the issue? https://github.com/jazzband/django-push-notifications
Also tried:
<service android:name="nl.hgrams.passenger.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
as in to give the full path. but still nothing.
Upvotes: 0
Views: 796
Reputation: 5830
The server part of the app was trying to send as Notification Message. This is what was causing the issue, and after I figured this out, I talked with the backend guy, in order to change the code to use Data Message, and now it works
Upvotes: 0