Support Topics Documentation Slack YouTube Blog

push notification - Android


(mohammed majeed) #1

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


(Anton Govorushkin) #2

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


(mohammed majeed) #3

Hi Anton,

Please check V 4 it still shows addpushnotification


(Sergey Chupov) #4

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 ) );

(Prashant Kain) #5

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


(Mark Piller) #6

Hi Prashant,

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

Mark


(Prashant Kain) #7

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


(Mark Piller) #8

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


(Prashant Kain) #9

I am using Backendless version 5.2.4


(Mark Piller) #10

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


(Prashant Kain) #11

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


(Mark Piller) #12

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


(Prashant Kain) #13

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


(Mark Piller) #14

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


(Prashant Kain) #15

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)


(Mark Piller) #16

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


(Prashant Kain) #17

I edit my above reply.
Please check it


(Mark Piller) #18

Hopefully this will help:


(Prashant Kain) #19

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)
}


(Mark Piller) #20

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