Push Notifications. How to get ID of published message? (Android)

Hello,
Is there some way to get ID of published message in BackendlessPushService onMessage( Context context, Intent intent ) method?
I use intent.getExtras() and got the bundle:

Bundle[{android-ticker-text=ticker text, com.backendless.messageid=2, google.sent_time=1487569045730, BL_VERSION_URL_PREFIX=v1, BL_PUBLISHER_ID=, android-content-text=content text, com.backendless.wakelockid=2, from="...", google.message_id="...", android-content-title=content title, message=Hello, BL_APPLICATION_ID="...", collapse_key=do_not_collapse, DSSubtopic=}]

there I can get headers, subtopic, publisher_id of message, but I need to get ID of the message. The field com.backendless.messageid = 2 isn’t looks like ID of message which we can get from Backendless.Messaging.publish(…) in MessageStatus field. I want to get the same ID format like on image.
http://support.backendless.com/public/attachments/b4e588afc55e3fef7667f742cb33c673.png</img>
Regards,
Alexander

Hello, Alexander.

You can use getMessageId() from MessageStatus. For more details please check https://backendless.com/documentation/messaging/android/messaging_publish_push_notifications.htm

Regards,
Olga

I can get message id from this method of MessageStatus object if I’m the sender of the message. But I want get message ID when I’m getting push-message from another user. So on my client side I get message using the documentation example (link):

import com.backendless.push.BackendlessPushService; 
 
public class MyPushService extends BackendlessPushService 
{ 
 
 @Override 
 public void onRegistered( Context context, String registrationId ) 
 { 
 Toast.makeText( context, "device registered" + registrationId, Toast.LENGTH_SHORT).show(); 
 } 
 
 @Override 
 public void onUnregistered( Context context, Boolean unregistered ) 
 { 
 Toast.makeText( context, "device unregistered", Toast.LENGTH_SHORT).show(); 
 } 
 
 @Override 
 public boolean onMessage( Context context, Intent intent ) 
 { 
 String message = intent.getStringExtra( "message" ); 
 Toast.makeText( context, "Push message received. Message: " + message, Toast.LENGTH_LONG ).show(); 
 // When returning 'true', default Backendless onMessage implementation will be executed. 
 // The default implementation displays the notification in the Android Notification Center. 
 // Returning false, cancels the execution of the default implementation. 
 return false; 
 } 
 
 @Override 
 public void onError( Context context, String message ) 
 { 
 Toast.makeText( context, message, Toast.LENGTH_SHORT).show(); 
 } 
} 



In onMessage( Context context, Intent intent ) method I haven’t MessageStatus object.

You can get message id only when publishing.
If you want to get the id of published message you should add this id as the additional info into the message header when publishing.

Regards,
Olga

Thanks for answer!

But I will know message ID only after publishing in success callback (method Backendless.Messaging.publish(…)) and I can’t add this field into header before publish. I really don’t understand how can I add the message id field into header when it genarates for every message on the server side…
When I used Pub/Sub Messaging I had the com.backendless.messaging.Message object in Backendless.Messaging.subscribe in handleResponse section. Where I was able to get mesage id. But when I started use Push notifications I have only Intent object with Bundle. There is no information about message ID, but exist another information like piblisher_id, headers etc.

You’re right, you can’t get message id before publishing.
However, you can create your own id (not message id) and put it into the message header.

Regards,
Olga

Thanks a lot, I got it,

It’s very sad that I can’t get this ID. I see that I can get headers, application id, subtopic and even the datetime when the massage was published, but not a message id. Is it a omission or not? I think it should be here.

You’re welcome.

Regards,
Olga