Backendless Support
 
Answered

"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,​

Leave a Comment

Comments (2)

photo
1

Hi Joan,

This is for getRegistration:

  1. Backendless.Messaging.getDeviceRegistration( new AsyncCallback<DeviceRegistration>()
  2. {
  3. @Override
  4. public void handleResponse( DeviceRegistration deviceRegistration )
  5. {
  6. System.out.println("Channels: " + deviceRegistration.getChannels());
  7. }
  8. @Override
  9. public void handleFault( BackendlessFault backendlessFault )
  10. {
  11. System.out.println("Error: " + backendlessFault.getDetail());
  12. }
  13. } );

Just swap Java 'sout' with toast, log or else.

Publish to single device async:

  1. List<String> devices = new ArrayList<>();
  2. devices.add( "some-device-id");
  3. DeliveryOptions deliveryOptions = new DeliveryOptions();
  4. deliveryOptions.setPushSinglecast( devices);
  5. PublishOptions publishOptions = new PublishOptions();
  6. publishOptions.putHeader( "android-ticker-text", "You just got a private push notification!" );
  7. publishOptions.putHeader( "android-content-title", "Backendless test" );
  8. publishOptions.putHeader( "android-content-text", "Targeted message (single cast)" );
  9. Backendless.Messaging.publish( channelName, "This is a private message!", publishOptions, deliveryOptions, new AsyncCallback<MessageStatus>()
  10. {
  11. @Override
  12. public void handleResponse( MessageStatus messageStatus )
  13. {
  14. System.out.println("Message status: " + messageStatus);
  15. }
  16. @Override
  17. public void handleFault( BackendlessFault backendlessFault )
  18. {
  19. System.out.println("Error: " + backendlessFault.getDetail());
  20. }
  21. } );

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:

  1. String whereClause = "deviceId = 'someId'";
  2. DataQueryBuilder queryBuilder = DataQueryBuilder.create();
  3. queryBuilder.setWhereClause( whereClause );
  4. Backendless.Data.of( "DeviceRegistration" ).find( queryBuilder, new AsyncCallback<List<Map>>()
  5. {
  6. @Override
  7. public void handleResponse( List<Map> maps )
  8. {
  9. maps.forEach( map -> System.out.println(map.get( "objectId" )));
  10. }
  11. @Override
  12. public void handleFault( BackendlessFault backendlessFault )
  13. {
  14. System.out.println("Error: " + backendlessFault.getDetail());
  15. }
  16. });

Best Regards

photo
1

okkkkkkkkkkkkkkk, many thanks.