Support Topics Documentation Slack YouTube Blog

Push notifications works from Firebase but not from Backendless

Backendless Version (3.x / 5.x, Online / Managed / Pro )

Online

Client SDK (REST / Android / Objective-C / Swift / JS )

REST

Application ID

E27B10A2-C4B9-A5A6-FF6A-AB65CBE35A00

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. Receive push notifications from Backendless (console and/or the Push Notifications API)

Actual Behavior

Hi

We have a Nativescript application which does not receive push notifications from backendless anymore.

Facts:

  1. Receiving push notifications from Firebase console works OK

  2. The device is successfully registered with Backendless with Backendless.Messaging.registerDevice methond (we receive a registration id and the device is visible in the Backendess online Data administration) alos the registered Firebase token is valid

However, Push notifications are not delivered from Backendless

We have a method that creates a push notification via the API Backendless.Messaging.publish and we receive a valid response with a message id back. However when we check the message status via POSTMAN the return is always message not found

{
“errorMessage”: “Could not find status for message with id: message:1B3213C5-F21E-4710-8E3B-556EE31EB6DC”,
“messageId”: “message:1B3213C5-F21E-4710-8E3B-556EE31EB6DC”,
“status”: “unknown”
}

We also try sending a push notification from Backendless Mesaging online interface but they are never delivered to our app.

Hello @Constantin_Craciunescu

Thanks for your report!

The device is successfully registered with Backendless with Backendless.Messaging.registerDevice methond (we receive a registration id and the device is visible in the Backendess online Data administration) alos the registered Firebase token is valid

Currently I can not see any registered devices in DeviceRegistration in your app so make sure you use Backendless.Messaging.registerDevice api correctly

However when we check the message status via POSTMAN the return is always message not found

yeah, message’s status is kept only a few minutes, try to check message status by its id right after publishing

for solving this issue we need a little bit more informations

  1. when did it stop working?
  2. how do you publish Push Notifications (to see code sample would be nice)
  3. configuration of your Remote Push Notifications Receiver

Regards, Vlad

Hi Vlad,
Strange, yesterday the device was registered and was showing in the data browser. I checked now and it was not there

I opened our app and my device got registered again

I believe we use the registerDevice method correctly because we do see the registration id and the Firebase token in the data browser

Device ID: b403871ba490fc87
Device token: f0RQ9J45RgQ:APA91bFbfwZSeqJgah5Qdm6crQVDvpRN5N0VrjUDKwtGa9lLykjXgyl5hmAQQR1ZRv8VeXI84VZLeF_Zc9imkhQO6-jKCqaJGvtzHIckhoknf2ca7c8tUhjY82upad81hInvgTicOr_L

Also in the Backelendless adminsitration->messaging->push notifications I am using push template to send a test message and I can see “Estimated number of recipients: 1”. And the “Message sent” toast message is displayed after we send the message:

And yes, I am checking for the status message right after it’s being sent. The result is always message not found, although when sending from the Backendless console it says Message sent.

I can send bits of our code but

  • same code worked before (it sopped couple weeks ago)
  • sending from Firebase works and our app receives the push notification;
  • when checking with POSTMAN the message API always returns message found

Thanks
Constantin

Strange, yesterday the device was registered and was showing in the data browser. I checked now and it was not there

Our system removes only devices with invalid device token on sending to FSM or APN services, so perhaps the device token was invalid and that’s why it was removed from Devices data table.

Do you use FirebaseSDK for receiving Push Notifications?

Hi Vlad,
Yes, we do you the firebase sdk and as mentioned several times Vlad, same code worked until weeks ago.

Also Vlad, as I mentioned several times, receiving from Firebase console works and I have just double checked the token that I have pasted above and which is stored at the moment is a valid token. I am able to receive from Firebase developer console using that token.

Sending from Backlendless shows message sent but there’s no way for us to check what happens with the message since the API messaging status check always returns message not found. (and yes we are checking right after the message is sent)

Regards
Constantin

Hi Constantin,

In order to receive push notifications from Backendless, you need to use Backendless SDK. You need to make sure that you register our service class in the Android manifest file per the instructions here:
https://backendless.com/docs/android/push_push_notification_setup_androi.html#appmanifest-configuration

Has it been done?

Regards,
Mark

Hi Mark
Yes, this has been done and we had this working. It all stopped couple weeks ago

Thanks

Hi Constantin,

We need to figure out where the break down is. We have re-run our tests which confirmed that push notifications are delivered successfully.

Could you please provide the following information:

  1. Your android manifest file
  2. Logcat, specifically when a push notification is sent

Regards,
Mark

Hi Mark,
Attached is the manifest file.
AndroidManifest.xml (2.1 KB)

Here’s the code that creates the notification by calling the Backendless messaging API

createNotification(publishOn: Date, title: string, text:string) {
let publishAt = new Date();

publishAt.setMinutes(publishAt.getMinutes() + 1);

console.log(“publish at”, publishAt);

var channel = “default”, message = “MotoCare Reminder”;

let publishOptions = new Backendless.PublishOptions({

headers: {

"android-ticker-text": "You just got a push notification",

"android-content-title": title,

"android-content-text": text

}

});

console.log(“publishOptions”, publishOptions);

let deliveryOptions = new Backendless.DeliveryOptions({

pushSinglecast: [this.deviceInformation.uuid],

publishAt: publishAt.getTime()

});

console.log(“deliveryOptions”, deliveryOptions);

Backendless.Messaging.publish( channel, message, publishOptions, deliveryOptions ).then( function( messageStatus ) {

console.log(“Scheduled push notification created”, messageStatus);

})

.catch( function( error: any ) {

console.log(“Backendless.Messaging.publish error”, error);

});
}

//----------------------- console output --------------------------------------------------

JS: publish at Mon Jan 06 2020 11:39:59 GMT+0200 (EET)
JS: publishOptions {
JS: “headers”: {
JS: “android-ticker-text”: “You just got a push notification”,
JS: “android-content-title”: “Reminder”,
JS: “android-content-text”: “Test reminder”
JS: }
JS: }
JS: deliveryOptions {
JS: “pushSinglecast”: [
JS: “e48e07235579072d”
JS: ],
JS: “publishAt”: 1578303599607
JS: }
JS: Scheduled push notification created {
JS: “errorMessage”: null,
JS: “messageId”: “message:B199B202-959C-4DBC-A7FF-505576995597”,
JS: “status”: "scheduled"
JS: }

As you can see in the console output we receive a message id from your API

Also, as a reminder the device is correctly registered in backendless and sending from Firebase console works

Thank You for your help,
Constantin

Hi Constantin,

Let’s try simplifying it as much as possible to make sure that push notifications in the most basic form are working. For example, I’d remove the pushSinglecast and and publishAt options for now. Could you please try that?

Regards,
Mark

I just tried, no luck

Also Mark, when I send from the Backendless Push Notifications Composer I see the Message Sent displayed but the push notification is not delivered to the app. Is there a way to find out if the message is sent from Backendless to Firebase?

Thanks

I’d like to try it with my device and your app. Could you please send me your google-services.json file? You can send it directly to me at mark@backendless.com. I think that’s all I need to be able to replicate your environment on my side.

What version of Android do you target in your build?

Regards,
Mark

Thanks Mark, I just sent you an email with the .json file attached. We are targeting Android 9 (api level 28)

Hi Consantine,

Here’s what I did:

  1. created the most basic Android app using the same package name as yours
  2. added google-services.json
  3. registered FCM dependencies
  4. added Backendless dependency
  5. Registered BackendlessFCMService
  6. Added code to do Backendless.initApp
  7. Added code to register device with Backendless
  8. Moved the app into the background - basically tapped the Home button in the emulator
  9. Used your test Push Template from your backendless app.

Here’s the result:

As you can see, a push notification is delivered just fine. I will zip-up the project file and email it back to you so you can compare the configuration with yours.

Regards,
Mark

Hi Mark

If I comment the service definition in AndroidManifest.xml

then the message from Backenless Console is “delivered” to my app I can print it out to the console

Also, another problem we always had related to the service declaration was that whenever the application is installed first time we get an error. Log-2020-01-07-15-42-47.txt (7.4 KB)

So, I believe we are not adding the Backendless Android SDK correctly?
At the moment we have the jar added as dependency in our app.gradle

Annotation%202020-01-07%20153518

But this does not seems to be enough/correct
Any idea where we should best add the backendless jar dependency?

Thank You
Constantin

Hi Constantin,

The way I have it in the project I shared with you is by importing Backendless SDK from maven as shown below (see the last line):

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-firestore:21.3.1'
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation group: 'com.backendless', name: 'backendless', version: '5.3.1'
}

That approach works for me as the BackendlessFCMService is recognized (Android Studio complains about any missing classes referenced in Android manifest).

Regards,
Mark

Hi Mark
If I drop the .jar file in App_Resources/Android/libs it will be picked up and added to the application dependencies. However I think we need a custom plugin to make the com.backendless.push.BackendlessFCMService service intent work.

For now we have the Backendless Console delivering the message to the app which is great and we will use the nativescript local-push-notifications plugin to create and display the notification.

Thanks again for all your help
Constantin