Questions about push notifications Android and REST

I am checking documentation about push notifications with Backendless, but i have some doubts about its general behavior and what i found in documentation:

  1. According to Android documentation (http://backendless.com/documentation/messaging/android/messaging_device_registration.htm), I have these options to register a device:

public void registerDevice( Context context, String GCMSenderID )

public void registerDevice( Context context, String GCMSenderID, String channel )

public void registerDevice( Context context, String GCMSenderID, List<String> channels, Date expiration )

But in Android SDK, registerDevice methods do not need Context param. Is the documentation wrong or do i have and outdated SDK?

  1. What is the correct flow to register a device? Should I check first if i have a current DeviceRegistration with a token? Or do i have to call Backendless.Messaging.registerDevice(gcmSenderID) every time I use the app, regardless if already registered the device?

  2. Is there an “automatic” way to register a device associated to a user? Or associate a specific token to a specific user? Or the only way is to create a field in Users table for the device token and update user with the obtained token? My goal is to register a user´s device and send it a push notification using REST API, but only to that specific user …

  3. Do you have any tutorials or demo codes about how to implement push messaging with Backendless?

Regards,
Andrés

Hi Andres,

The “context” argument is not needed, we will update the docs to reflect that.

Device registration can be done only once, there is no need to do that every time.

In order to link a user with his device registration, you would need to associate User object with the value in:

for Android:

com.backendless.Messaging.DEVICE_ID 

for iOS:

[backendless.messagingService currentDevice].deviceId

This is the value you should use when you target a specific device in a push notification.

As for the sample code, there should be a project included into the SDK and you can also use the Code Generator to create a sample project with this functionality.

Regards,
Mark

Thanks Mark! I totally forgot that the SDKs have sample code, i will check them.

Regards,
Andrés

Hi Mark.

I have registered one Android device for notifications. Now i would like to send a test notification using Admin Console, but I always get “Authentication failed” message in screen. I am attaching screenshots.

What is the right way to send a push notification from Admin Console?

Regards,
Andrés

Hi Andres,

A couple of questions:

  1. Have you gone through the backend setup as documented here?:
    http://backendless.com/documentation/messaging/android/messaging_push_notification_setup_androi.htm

  2. When you publish a push notification to an Android device, you need to provide special message headers using the Headers field in console. Also, you need to select the “Push Notification” checkbox. The headers are documented here: http://backendless.com/documentation/messaging/android/messaging_publish_push_notifications.htm

Regards,
Mark

Hi Mark.

I have checked the setup and i was doing it wrong, sorry to bother you. I was saving an Android API key instead of a Server API key. Now i have changed it and tried to send again a test notification to the only device i have registered. I got the OK message in console, but i didn´t receive it in the device.

I have checked that the Android manifest configuration is correct, so i think it is due to the headers field like you said, but i don´t understand very well how do i have to fill it in admin console. Could you please give me an example?

Regards,
Andrés

Hi Andrés,

When you publish a message as a push notification through Backendless Console, header values (for the Android devices) should look like this:

"android-ticker-text":"this is ticker text", "android-content-title":"this is content title", "android-content-text":"this is context text"

Hope this helps.

Regards,
Mark

i have made all steps written on the DOC and i have the same problem look to my attachment
I got the OK message in console, but i didn´t receive it in the device.

Hi!

Do you see your device on console in list of registered devices?
If yes - then verify that all required headers are sent:

"android-ticker-text":"this is ticker text", "android-content-title":"this is content title", "android-content-text":"this is context text"

If not - then try to call register() method again and check Google credentials in your app and in console.
Also try to reproduce the problem using codegeneration and backendless sample from github: https://github.com/Backendless/Android-SDK/tree/master/samples/MessagingService.

best regards,
Alex

Hi,
I am trying to publish a message using the snippet that I found, but it’s returning me
BackendlessException{ code: ‘Internal client exception’, message: ‘null’ }

I have performed the following code:

DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushPolicy(PushPolicyEnum.ONLY);
deliveryOptions.setPushBroadcast(PushBroadcastMask.ANDROID);

PublishOptions publishOptions = new PublishOptions();
publishOptions.putHeader(“android-ticket-text”, “You just got a push notification!”);
publishOptions.putHeader(“android-content-title”, “This is a title in notification center”);
publishOptions.putHeader(“android-content-text”, “Text of the notification message in the notif. center”);

MessageStatus status = Backendless.Messaging.publish(“Hey Android!”, publishOptions, deliveryOptions);

if (status.getStatus() == PublishStatusEnum.FAILED){
System.out.println("@@ FAILED");
}
else if (status.getStatus() == PublishStatusEnum.PUBLISHED){
System.out.println("@@ PUBLISHED");
}
I have done the code for device registration before the above code. The exception takes me to the line that I have made underline.

I have done the push notification using console na working well, so now I am trying using code.

Hopeful for your kind and quick reply.Thanks in advance.

I have the exact same problem as Jay Joshi. i was also able to send the push notification from the console. Any ideas why the publish method crashes with that internal code?

ok, i was able to solve the problem with the same calling like in the screenshot http://support.backendless.com/attachments/1608