Hi,
I’ll try to explain my problem, I’m sending a message to a channel with a subtopic successfully however i would like to send it with a push notification, i was also able to do that with no problems, on the other hand i have a small problem with the fact that, even when the receiver is currently on the chat window and he will actually be able to see that message in a second, the message is still being sent with the push notification. Is there any method to control this? i’ve tried with the message status wich is always “scheduled” in the handleResponse method so i can’t really control it over there. My main purpose is for the message to be sent through a push notification if the receiver is not currently on the chat window. Any suggestions? i already thought about modifying some server code and use the afterPublish method, but i’m wondering if there is another easier way? i’m attaching the method that i use for sending the message.
Thanks in advance guys.
publishOptions = new PublishOptions();
publishOptions.setPublisherId( FstUserName);
publishOptions.setSubtopic( subtopic );
publishOptions.putHeader( PublishOptions.ANDROID_TICKER_TEXT_TAG, String.format( ConstantsClass.MESSAGE_SEND, MainActivity.user.getName() ) );
publishOptions.putHeader( PublishOptions.ANDROID_CONTENT_TITLE_TAG, getResources().getString( R.string.app_name ) );
publishOptions.putHeader( PublishOptions.ANDROID_CONTENT_TEXT_TAG, String.format( ConstantsClass.MESSAGE_SEND, MainActivity.user.getName() ) );private boolean onSendMessage( int keyCode, KeyEvent keyEvent )
{
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushPolicy( PushPolicyEnum.ALSO );
deliveryOptions.addPushSinglecast( UsrsDeviceIDs);
if( keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_UP )
{
String message = messageField.getText().toString();
if( message == null || message.equals( "" ) )
return true;
Backendless.Messaging.publish( (Object) message, publishOptions,deliveryOptions, new DefaultCallback<MessageStatus>( ChatActivity.this, "Sending..." )
{
@Override
public void handleResponse( MessageStatus response )
{
super.handleResponse( response );
PublishStatusEnum messageStatus = response.getStatus();
if( messageStatus == PublishStatusEnum.SCHEDULED )
{
messageField.setText( "" );
}
else
{
Toast.makeText( ChatActivity.this, "Message status: " + messageStatus.toString(), Toast.LENGTH_SHORT );
}
}
} );
return true;
}
return false;
}