"backendless.messaging publish" & "getDeviceRegistration" ...

Hi,
Can you provide me the complete skeleton of the code of these two asynchronous android sentences?:

1.- “backendless.messaging publish”.
To send to a specific device with the device identifier.

2.- "getDeviceRegistration".
     To retrieve the device identifier.


Both are not clear to me in the documentation …​

Regards,​

Hi Joan,

This is for getRegistration:

Backendless.Messaging.getDeviceRegistration( new AsyncCallback<DeviceRegistration>()
{
@Override
public void handleResponse( DeviceRegistration deviceRegistration )
{
System.out.println("Channels: " + deviceRegistration.getChannels());
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
System.out.println("Error: " + backendlessFault.getDetail());
}
} );

Just swap Java ‘sout’ with toast, log or else.

Publish to single device async:

List<String> devices = new ArrayList<>();
devices.add( "some-device-id");
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushSinglecast( devices);
PublishOptions publishOptions = new PublishOptions();
publishOptions.putHeader( "android-ticker-text", "You just got a private push notification!" );
publishOptions.putHeader( "android-content-title", "Backendless test" );
publishOptions.putHeader( "android-content-text", "Targeted message (single cast)" );
Backendless.Messaging.publish( channelName, "This is a private message!", publishOptions, deliveryOptions, new AsyncCallback<MessageStatus>()
{
@Override
public void handleResponse( MessageStatus messageStatus )
{
System.out.println("Message status: " + messageStatus);
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
System.out.println("Error: " + backendlessFault.getDetail());
}
} );

Again, sout needs to be adapted to Android environment. Since we’ve introduced new system table “DeviceRegistration” (located in Data console, along with Users table) you can manage your registrations via Data (Persistence) API. F.E you can get the necessary registration just by executing search with query to “DeviceRegistration” table. F.e:

String whereClause = "deviceId = 'someId'";
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause( whereClause );
Backendless.Data.of( "DeviceRegistration" ).find( queryBuilder, new AsyncCallback<List<Map>>()
{
@Override
public void handleResponse( List<Map> maps )
{
maps.forEach( map -> System.out.println(map.get( "objectId" )));
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
System.out.println("Error: " + backendlessFault.getDetail());
}
});

Best Regards

okkkkkkkkkkkkkkk, many thanks.