push notification - Android

Hi,

I am trying to push a notification to a specific device using API provided by your documentation, I followed the instructions and tried:
deliveryOptions.addPushSinglecast( receiver-device-id );

but addPushSinglecast is not available, I found setPushSinglecast instead, which requires list <String> as argument

I could not find any documentation/examples on how to use this

Can you please provide some help/

Thanks,
Mohammed

Hi Mohammed,

The documentation you are referencing is for version 3 of Backendless (see attached screenshot). In Backendless 4 you should use setPushSinglecast method which accepts list <String> argument. Docs for message publishing in Backendless 4: https://backendless.com/docs/android/doc.html#messaging_publish_push_notifications

Regards, Anton

Hi Anton,

Please check V 4 it still shows addpushnotification

Hi Mohammad,

Thank you for pointing that! I have created an internal documentation ticket (ID: BKNDLSS-16817) to fix this.
As for the usage, you only need to form a List now in version 4, e.g.:

deliveryOptions.setPushSinglecast( Arrays.asList( receiver-device-id ) );

Hi Sergey ,
I do as you stated but setPushSingleCast does not helping me to send push notifications to a specific device instead it sends to all devices in channel after putting device id of reciever in setPushSingleCast.
Please Help me in this.
Thanks,
Prashant

Hi Prashant,

See the example here:
https://backendless.com/docs/android/push_target_specific_devices.html

Mark

Thank You Mark.
But the link you provided uses addPushSinglecast method which is not available in version 5 .
Please Help me in this.
Thanks,
Prashant

Version 5 is what we currently have in Backendless Cloud. What version are you using?

I am using Backendless version 5.2.4

On the server side? Or is this the version of the client SDK?

implementation group: ‘com.backendless’, name: ‘backendless’, version: ‘5.2.4’
I use this in my build.gradle file (Module : app)

That’s the version of the client side library. So what’s the problem with the documentation link?

Please Read this Mark,
I want to send a push notification only to a specific device registered but the example in link : https://backendless.com/docs/android/push_target_specific_devices.html uses addPushSinglecast method of DeliveryOptions class which is not available for Backendless version 5.2.4 whereas setPushSinglecast method of DeliveryOptions is also not helping as it sends notification to all devices registered in the channel.
Thanks for helping me in this

setPushSinglecast accepts an array of string values. Each value must be device ID of the device which will be receiving the notification. Is this how you use the API?

Regards,
Mark

Yes! I am pretty sure using the way you are stating.
Here is the code:

//List for getting device id
final List<String> devId = new ArrayList<String>();
DataQueryBuilder queryBuilder=DataQueryBuilder.create();
queryBuilder.setWhereClause(“user.name = '” +friend+ “’”);
//Searching an object of DeviceRegistration Table matching with friend name in
//Users table
Backendless.Data.of(“DeviceRegistration”).find(queryBuilder, new AsyncCallback<List<Map>>() {
@Override
public void handleResponse(List<Map> response) {

//if found friend registered the device
if(!response.isEmpty()) {
Map friendId = response.get(0);
devId.add((String) friendId.get(“deviceId”));
}
}
@Override
public void handleFault(BackendlessFault fault) { }
});

DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushSinglecast(Arrays.asList(devId.get(0)));
publishOptions.putHeader(“android-content-title”,user);
publishOptions.putHeader(“android-content-text”,message);
Backendless.Messaging.publish(“ChitChatChannel”, message,
publishOptions, deliveryOptions)

I am curious, how do you get the device id of the device which should be receiving the notification?

I edit my above reply.
Please check it

Hopefully this will help:

No No,
I put it at as
if(!devId.isEmpty())
{
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushSinglecast(Arrays.asList(devId.get(0)));
publishOptions.putHeader(“android-content-title”,user);
publishOptions.putHeader(“android-content-text”,message);
Backendless.Messaging.publish(“ChitChatChannel”, message,
publishOptions, deliveryOptions)
}

Please verify in the debugger that you’re setting a value in the setPushSinglecast call.