Backendless Support
 
Waiting for user's response

Push Notification from Console not being delivered to client

Hi,

I have added my Firebase Server Key correctly to Backendless Mobile Settings. I am also able to register my device via REST Api with the "deviceId" and "deviceToken" received from Firebase, which is my messaging service provider, as per the REST documentation similar to the below curl.

  1. curl \
  2. -H Content-Type:application/json \
  3. -X POST \
  4. -d '{ \
  5. "deviceToken":"XXXXXXXXXXXXXXXXXXXXXXXXX", \
  6. "deviceId":"XXXXXXXXXXXXXXXXXXXXXXXXX", \
  7. "os":"ANDROID", \
  8. "osVersion":"4.1" \
  9. }' \
  10. -v https://api.backendless.com/XXXX-XXXX-XXXX/ZZZZ-ZZZZZ-ZZZZZ/messaging/registrations

I notice the REST Api does not have a provision for sending the GCMSenderId similar to the native Backendless SDK device registration call below. Please confirm it's not required for REST Api.

  1. Backendless.Messaging.registerDevice( GCMSenderId, String Channel);

I am however not able to publish from Backendless console to the device, the message simply does not get delivered. I am assuming Backendless requests Firebase, my service provider, to send the notification to the target user as identified by the deviceId/deviceToken, so my client is set up to receive the notification in the onMessageReceieved callback of Firebase's receiver, but nothing is received.

In any case is my Firebase server key enough for Backendless to know that i am using Firebase Cloud Messaging as my messaging service provider so as to direct the requests for delivery to the device there?

Regards,

George

Leave a Comment

Comments (8)

photo
1

Hi Odhiambo,

Please confirm I understand the use-case correctly:

  1. You register the device using REST API
  2. You send the push notification from the developer's console, the Messaging tab

If this is the case, please provide the following:

  1. How do you retrieve deviceId and deviceToken to send along with a REST request?
  2. Do you make sure you send the notification from "Devices" tab, not from "Messages" tab?
  3. How did you configure the receiver in your Android app?

photo
1

Odhiambo,

The way you are registering a device via REST will create an additional column "os" in DeviceRegistration table (if it did not exist). You are not sending a required parameter "operatingSystemName", value of which should be "ANDROID". In your case you are creating a DeviceRegistration object with a value for "operatingSystemName" - "UNKNOWN" and this device will not be visible in devices tab (messaging). As a result messages are not delivered. Update your REST request and try again. If it still will not work for you - please answer Sergey's questions

Regards,

Anton

photo
1

Hi,

Am getting the deviceId as follows

  1. // get device id
  2. String deviceId;
  3. String builder = System.getProperty("os.name") +
  4. System.getProperty("os.arch") +
  5. System.getProperty("os.version") +
  6. System.getProperty("user.name") +
  7. System.getProperty("java.home");
  8. deviceId = UUID.nameUUIDFromBytes(builder.getBytes()).toString();
  9. Log.d(TAG, "currentdeviceId " + deviceId);

Am getting the deviceToken by overriding this callback in MyFirebaseInstanceIDService class

  1. @Override
  2. public void onTokenRefresh() {
  3. // Get updated InstanceID token.
  4. String refreshedToken = FirebaseInstanceId.getInstance().getToken();
  5. Log.d(TAG, "Refreshed token: " + refreshedToken);
  6. // send to app server.
  7. registerDevice(refreshedToken);
  8. }

Then am creating the Request Body as follows

  1. JsonArray channels = new JsonArray();
  2. channels.add(currentUserId);
  3. Log.d(TAG, "channels:" + channels);
  4. JsonObject requestBody = new JsonObject();
  5. requestBody.addProperty("deviceToken", refreshedToken);
  6. requestBody.addProperty("deviceId", deviceId);
  7. requestBody.addProperty("os", "ANDROID");
  8. requestBody.addProperty("osVersion", String.valueOf(Build.VERSION.SDK_INT));
  9. requestBody.add("channels", channels);
  10. Log.d(TAG, "doRegisterDevice, jsonObjectBody " + requestBody);

Headers

  1. Map<String, String> headermap = new HashMap<>();
  2. headermap .put("Content-Type", "application/json");
  3. headermap .put("user-token", currentUserToken);

Then using Retrofit to do the POST

  1. @POST("messaging/registrations")
  2. Single<RegistrationId> registerDevice(@HeaderMap Map<String, String> headermap, @Body JsonObject requestBody);

RegistrationId is the response

In Backendless, the device is registered with all parameters including the operating system name, see attached file.

Please confirm that Backendless is sending the properly formated HTTP requests containing my Server Key to this endpoint for Firebase Cloud Messaging:

  1. https://fcm.googleapis.com/fcm/send

and not

  1. https://gcm-http.googleapis.com/gcm/send

for Google Cloud Messaging.

Regards,

George

photo
1

As for the GCM sender id - it's not needed for registering devices via REST API.

Do you mind if I try registering a test device to your app/channel? I will delete it when the test will be finished.

For the test we'd need:

1) your application id.

2) your GCM sender id (you may send it to support@backendless.com if you don't want to share it publicly)

3) please share implementation of your registerDevice(refreshedToken); method

Regards,

Anton

photo
photo
1

Hi Anton,

I have sent to the email provided.

It's ok you can register a test device to my app/channel

Regards,

George

photo
1

Hi again George

From what I see in your application you have a key configured for default channel only. So when you are registering a device to any other channel (channels.add(currentUserId); in your case) messages shall not be delivered. Delete your key and add it again, but select all channels this time and repeat your tests again.

Regards Anton

photo
1

Hello Anton,

I can get the message in my client now, takes time though, is that the normal behavior for messages sent from console?

Regards,

George

photo
1

Depends on how much it takes. Could you please share the exact time?

Anton