Push notifications without sound

When I send a push notification to a Android device from the Backendless platform, on the phone I receive the notification but it does not make any sound.
Just to make sure that my phone is all right, I sent a push notification from parse and when I receive the notification the phone makes a sound normally.

Why when sending a push notification from backendless the phone does not makes any sound? It is happening on android device. I have not tested on IOs since I don´t have ios operative system.

What are the values of the headers you’re sending to play a sound?

I do not think our broadcast receiver supports sound playback out of the box.

The header I´m using is:
“android-ticker-text”:“Ticker”, “android-content-title”:“tittle”, “android-content-text”:“text”

Thanks for your quick reply :wink:

There is really nothing in these headers which would cause a phone to play a sound.

So, what should I add in the header to cause a phone to play a sound when receiving the notification?
what should the header look like?

There is no special header to play a sound. This would need to be added to the broadcast receiver class.

You would need to extend this class:
https://github.com/Backendless/Android-SDK/blob/master/src/com/backendless/push/BackendlessBroadcastReceiver.java

override the “onMessage” method in your subclass. Then implement the approach described here:

Thanks I´ll try that solution

If I only write the message in the message field without any header the push notification don’t have sound…
How can I play the notification sound without any header?
Parser works in this way.

you can not.

Mark has answered the question.

I finally did not get the sound when I get a notification. Don´t know how to do it.

If anyone did it and want to share an examlpe code would be great!

Ok, now I see your points. It is really not so easy with backendless, I have created an internal ticket to simplify this. As work around you can create your own BackendlessPushService here is a doc how to do it https://github.com/Backendless/Android-SDK/blob/master/docs/push.md .

then you should override method onMessage in next way

public boolean onMessage( Context context, Intent intent )
{
  CharSequence tickerText = intent.getStringExtra( PublishOptions.ANDROID_TICKER_TEXT_TAG );
  CharSequence contentTitle = intent.getStringExtra( PublishOptions.ANDROID_CONTENT_TITLE_TAG );
  CharSequence contentText = intent.getStringExtra( PublishOptions.ANDROID_CONTENT_TEXT_TAG );

  if( tickerText != null && tickerText.length() > 0 )
  {
    int appIcon = context.getApplicationInfo().icon;
    if( appIcon == 0 )
      appIcon = android.R.drawable.sym_def_app_icon;

    Intent notificationIntent = context.getPackageManager().getLaunchIntentForPackage( context.getApplicationInfo().packageName );
    PendingIntent contentIntent = PendingIntent.getActivity( context, 0, notificationIntent, 0 );
    Notification notification = new Notification.Builder( context )
            .setSmallIcon( appIcon )
            .setSound( &lt;URI to your sound&gt; ) <- provide your sound
            .setTicker( tickerText )
            .setContentTitle( contentTitle )
            .setContentText( contentText )
            .setContentIntent( contentIntent )
            .setWhen( System.currentTimeMillis() )
            .build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    int customLayout = context.getResources().getIdentifier( "notification", "layout", context.getPackageName() );
    int customLayoutTitle = context.getResources().getIdentifier( "title", "id", context.getPackageName() );
    int customLayoutDescription = context.getResources().getIdentifier( "text", "id", context.getPackageName() );
    int customLayoutImageContainer = context.getResources().getIdentifier( "image", "id", context.getPackageName() );
    int customLayoutImage = context.getResources().getIdentifier( "push_icon", "drawable", context.getPackageName() );

    if( customLayout > 0 && customLayoutTitle > 0 && customLayoutDescription > 0 && customLayoutImageContainer > 0 )
    {
      NotificationLookAndFeel lookAndFeel = new NotificationLookAndFeel();
      lookAndFeel.extractColors( context );
      RemoteViews contentView = new RemoteViews( context.getPackageName(), customLayout );
      contentView.setTextViewText( customLayoutTitle, contentTitle );
      contentView.setTextViewText( customLayoutDescription, contentText );
      contentView.setTextColor( customLayoutTitle, lookAndFeel.getTextColor() );
      contentView.setFloat( customLayoutTitle, "setTextSize", lookAndFeel.getTextSize() );
      contentView.setTextColor( customLayoutDescription, lookAndFeel.getTextColor() );
      contentView.setFloat( customLayoutDescription, "setTextSize", lookAndFeel.getTextSize() );
      contentView.setImageViewResource( customLayoutImageContainer, customLayoutImage );
      notification.contentView = contentView;
    }

    NotificationManager notificationManager = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE );
    notificationManager.notify( intent.getIntExtra( BackendlessBroadcastReceiver.EXTRA_MESSAGE_ID, 0 ), notification );
  }

  return false;
}

it is important to return false. because you will duplicate push notification

Thank you for your reply. I´ll try to do it in that way.

From my point of view, backendless should provide an easier way of doing that (like in parse, by default the receive of a push notification sent with parse comes with sound).
If the ticket that you just opened makes the backendless team to provide a solution in a version update or something, please, let me know.

Thanks!