Receive PUSH notification in custom Receiver extending BackendlessBroadcastReceiver.

I am able to receive push notification by using the default “BackendlessBroadcastReceiver” receiver.
I intent to receive PUSH notification in a custom receiver.

I have declared my receiver in Manifest as below-

<receiver
    android:name=".PushReceiver"
    android:permission="com.google.android.c2dm.permission.SEND">
    &lt;intent-filter&gt;
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

        &lt;category android:name=&quot;xxx.xxx.xxx&quot; /&gt;
    &lt;/intent-filter&gt;
&lt;/receiver&gt;

PushReceiver as follows below -

public class PushReceiver extends BackendlessBroadcastReceiver {

    @Override
    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 );
        String message = intent.getStringExtra( PublishOptions.MESSAGE_TAG );

        android.support.v4.app.NotificationCompat.Builder mBuilder =
                new android.support.v4.app.NotificationCompat.Builder(context)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle(contentTitle)
                        .setContentText(contentText)
                        .setTicker(tickerText)
                        .setAutoCancel(true)
                        .setOngoing(true)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        mNotificationManager.notify(1, mBuilder.build());

        return true;
    }

}

I’m not sure whether PUSH notification are received or not but the notification is not displayed.

Hi Ketan,

Sounds like you’re asking us to debug your code… :wink: We’d be happy to do it, but that would be outside of support. Contact sales@backendless.com to discuss your options.

Mark

Hi Mark. Nah I would like to know that what I did is it correct or not?

Ketan,

Please understand, we provide support for our APIs and backend. When you start customizing things this goes outside of the support charter. If I says “yes, what you did is correct”, but if things will not work - you will say “what did I do wrong?”. The source code for our receive is right there. You’re welcome to debug your code (and ours if you want to), however, when it comes to reviewing derivatives from our code, this is where we draw the line for free support.

Mark

Hello Mark, I’m interested in displaying the Push “Message” in Android Activity. Can you please tell me how to do that using default “BackendlessBroadcastReceiver”.

Sure, take a look at the following code:

BackendlessBroadcastReceiver calls onMessage. If the method returns false, then the default visualization logic is disabled. In your implementation of onMessage you can do whatever you want with the push notification.

Okay. Thanks Mark.