Trouble with receiving push notifications on Android

We already tried to solve the issue back in january, but could not get it to work. (Trouble receiving push notifications on Android) Now we are trying to properly implement the push notifications for Android again. Sadly it still does not work.

The firebase messgaing client seems to be correctly configured, because messages sent from the Firebase dashboard are received on all devices. When specifiying a channel (eg. APPID_group_GROUPUID) and sending a message from the Firebase dashboard, all devices subscribed to the channel successfully receive the message.

Only when sending messages with Cometchat, no push notifications are received. Firebase Cloud Messaging analytics also does not show that any notification was sent. Therefore we think, that Cloud Messaging does not receive requests from the Cometchat servers. We already double checked our Firebase API key in the push notification extensions settings, but it seems to be the right one.

Is there any way to test if Cloud Messaging receives requests from Cometchat?

Sincerely,
Jan G.

Hi @Jan,

Can you share your FirebaseService.java file where you have implemented your firebase methods. So that we can check at our end and help you to resolve your issue.

My MyFirebaseMessagingService.java like like this:

import com.google.firebase.messaging.FirebaseMessagingService;

public class MyFirebaseMessagingService extends FirebaseMessagingService {

}

Again, I do not think its a Problem with our Firebase configuration on the client side, because Messages sent from the Cloud Messaging dashboard are received. This is also true for messages sent to a specific channel the user subscribed to.

Hi @Jan,

Seems like your MyFirebaseMessagingService.java is empty. You need to add onMessageReceived(RemoteMessage remoteMessage) firebase method and to receive messages of push notification and create notification based on the message.

Please refer the below MyFirebaseMessagingService.java

We have implemented the onMessageReceived(RemoteMessage remoteMessage) method:

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.d("MESSAGE", remoteMessage.toString());

        try {

            BaseMessage baseMessage = CometChatHelper.processMessage(new JSONObject(remoteMessage.getData().get("message")));

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this,"2")
                    .setContentText("Test Content")
                    .setContentTitle("Test Title");

            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

            notificationManager.notify(baseMessage.getId(), builder.build());

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

Sadly we still run into the same issue. Messages sent from the Cloud messaging dashboard are working perfectly. When creating a new message on the Cloud Messaging dashboard and specifiying a channel (e.g. APPID_group_2398425) every client subscribed to the channel receives the message. When a message gets send in a group (e.g. with the uid 2398425), no notification gets sent and the count on the Cloud Messaging dashboard does not increase.

Edit: As far as I understand, onMessageReceived also only gets called when the app is in foreground. We would like to notify the user when it is in background.

When the app is open and a message is sent via the Cloud Messaging Dashboard (Firebase console), the method posted in the previous post runs. When sending a message with Cometchat and the app is open, the method does not run. That is why we think Cloud Messaging does not receive messages from CometChat. This could mean the Cloud Messaging server key given to Cometchat is wrong (should not be the case, checked the key multiple times). Is there a way to test if API calls from CometChat are received by Firebase?

Hi @Jan,

The MyFirebaseMessagingService.java works for background also. If you have added it as a service in the manifest. Please check whether you have added service MyFirebaseMessagingService.java as service in AndroidManifest.

<service
    android:name=".MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Please refer the below link for more details.
https://firebase.google.com/docs/cloud-messaging/android/client

Hey,

our Firebase Messaging Service seems to be configured correctly:

<service
   android:name=".Services.MyFirebaseMessagingService"
   android:exported="false">
    <intent-filter>
      <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Again: The Problem is not receiving messages on the device. Everything sent by Cloud Messaging is received perfectly fine. The only problem is, that it seems like CometChat does not send any messages to the Cloud Messaging Platform and therefore Messages obviously cannot be received by devices.

Do you have any other ideas why it would not work? Can I somehow verify that Cloud Messaging receives messages from the CometChat Servers?

Hey,

we are still facing the issue. Do you have an idea how we could verify that Cloud Messaging receives messages from the CometChat Servers?

Hi @Jan,

We suggest you refer our code present in the previous post.


Also please make sure that you have subscribed to a group.

Firebase cloud messaging platform does not list the push notification sent via REST API. To confirm that the push notifications are being sent successfully, Please check the Report under Cloud Message section in Firebase console. PFA this screenshot.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.