Hi Oleg, OK I got that, but I am missing something in the jigsaw puzzle. I would like to be able to change the destination of the activity in this method. So rather than going to the main activity I would like it to go another activity. Tried below but it still goes to the main activity. Any ideas what am I doing wrong. Understand this might be outside of backendless here, but perhaps a quick glance if I am doing something fundamentally wrong or in the wrong place but would be very helpful.
This is what I have (abbreviated for clarity)
@Override
public boolean onMessage(Context appContext, Intent msgIntent) {
// confirm yes we get here when message received.
NotificationManager mNotificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE);
// put the Activity here that you want to open when you click the Notification
Intent notificationIntent = new Intent(appContext, PushNotification.class);
PendingIntent contentIntent = PendingIntent.getActivity(appContext, 0, notificationIntent, 0);
NotificationCompat.Builder notification = new NotificationCompat.Builder(appContext,"default");
notification.setContentTitle(messageTitle).setContentText(message).setSmallIcon(R.drawable.icon);
notification.setContentIntent(contentIntent);
mNotificationManager.notify(0, notification.build());
return true;
}
As i understood, you want to show the message in the notification bar.
Have you tried to do this with the notification template? E.g. you could try to add the button (on the template) and attach your activity to it. Or you want go there at the tap on the notification itself ?
Howbeit, try with the button, it maybe the start point.
ps. at first sight your code is correct, but I didn’t debug it.
Hi Oleg, no I want to go there at the tap of the notification itself.
The problem with the button route on the template is that we don’t use buttons on our push notifications. We just need to be able to click on the notification like normal but go through to a different activity not the main/home activity.
Also talking about template functionality if you setup a template in the console you can call it very easily with Backendless.Messaging.pushWithTemplate( templateName )
but was wondering if you could pass it optional paramaters on the api call to the template too? That would mean you could set a template for specific customers and then just change parts of the content of the message quite easily. like Backendless.Messageing.pushWithTemplate( templateName, title)
If you want to redirect the user to another activity, you should create your own service that will extend BackendlessFCMService and manually build the notification. Here is a rough example:
The SecondActivity is the Activity I want to open when the user click the notification: Intent notificationIntent = new Intent(getApplicationContext(), SecondActivity.class);
Also don’t forget to define your service in the manifest:
For channelName, can I somehow get this from this in the msgIntent which is passed into the override onMessage. So if a channel is set in the message template I would like to pick it up here and I can’t find a way of doing that?
Strange thing is template name is returning as ‘ImmediateMessage’
In the backendless console I have setup a template called ‘android_developer_phone_test’ , created and added a channel called testChannel to this template.
So you would expect it to return ‘android_developer_phone_test’ correct ? I don’t have any channels or templates called ‘ImmediatMessage’ so confused as where that is coming from.
You receive the “ImmediateMessage” name if you send the notification from Console.
When you send the notification using API Backendless.Messaging.sendWithTemplate() you will receive the real template name.