How can I launch an activity when my users click on push notifications? I saw some code fragment but they were for notification received and not notification clicked.
Java, Android
You need to setup Actions on Tap
field here:
There you should put the full name of the Activity class.
Regards,
Stanislaw
it seems like if I define an activity in the push notifications template then I have to specify a channel or segment. But I cannot determine the channel or segment am sending to except in code. And it seems I don’t get any variables passed along to the activity so that the activity can open in context knowing exactly what to show
Please describe your case in more detail, at this point I don’t quite see what exactly you are trying to do. Do you want several different actions when clicking on your push notification? Maybe you should add buttons, clicking on each will perform a specific action.
Regards,
Marina
My push notifications will have different context. For example a user might get a push notification informing them of the status of another user, in this case when the notification is clicked I want it to open that users profile page in the profileActivity. This particular notification goes to this specific user via their specified push notification channel (which is already defined in their profile) What this means is that I need a variable passed along with the notification that holds the user’s username so as to be able to open their profile page. Also I might send promotional notifications, in this case clicking it should open the promoActivity.
You can do this using the Activity class. In which you need to specify all the necessary logic. Here is an example of how this can be implemented.
Android Notification Buttons - Backendless SDK for Android/Java API Documentation
This logic can be used not only on buttons, but also on Action on tap.
Regards,
Marina
I now understand how to receive the push notification with buttons and extract all the information associated with it, but how do I create the notification all in code?. I saw this
"The content of a push notification comes from the push template from which a push notification is created. " And am wondering can’t I create a push notification with buttons all in code(without creating from template)? The reason why I want to create it in code is because that is only where I can determine the push notification channel to send to.
When you create notification in the code, you can set additional headers, which will be sent with the notification itself and be accessible in the Activity.
Also look through the smart-text (when the information can be dynamic depending on the user).
Please show me sample code how to create push notification with buttons.
What do you mean saying “push notification with buttons”.
Maybe we are talking about different things?
Push notification (from the perspective of Backendless) consists of two parts.
- The first one is just information which is sent to the end device.
- The second is the visual presentation of the information (where you can crate buttons and bind them with the Activities which will handle the events).
For visualization the Push Template is responsible.
If you do not want to use our PushTemplate you may use “silent notification” and the PushTemplate visualization will be disabled. In such a case you receive only the raw message and then it is your responsibility what to do with that data. Thus, you have to implement all the logic by yourself (use official Android documentation).
Doesn’t using a push template force me to specify a push channel? My problem is that I can only know the push channel to send to in code. It seems there is something very basic am missing.
This is sample code for creating push notification without template
PublishOptions publishOptions = new PublishOptions();
publishOptions.putHeader( “android-ticker-text”, “You just got a push notification!” );
publishOptions.putHeader( “android-content-title”, “This is a notification title” );
publishOptions.putHeader( “android-content-text”, “Push Notifications are cool” );
MessageStatus status = Backendless.Messaging.publish( (Object) “Hi Devices!”,
publishOptions );
Where do I specify the buttons to add?
For the visualization PushTemplates are responsible. And yes, they are bound to the channel. You may create several templates for different needs.
“My push notifications will have different context. For example a user might get a push notification informing them of the status of another user, in this case when the notification is clicked I want it to open that users profile page in the profileActivity. This particular notification goes to this specific user via their specified push notification channel (which is already defined in their profile) What this means is that I need a variable passed along with the notification that holds the user’s username so as to be able to open their profile page. Also I might send promotional notifications, in this case clicking it should open the promoActivity.”
So you mean my use case is not possible?
As Marina mentioned before, you may set the Activity which will be called on user tap. And there you are free to implement any logic you want. That is your case.
Did you have at least minimum working example with PushTemplate and some Activity to handle actions? I think you need to play a little bit with them for better understanding how it works.
I have been able to work with pushWithTemplate but the button is not responding to taps.
The notification itself calls the “Action On Tap” activity when clicked.
If i was calling push notification without template i would set headers in PublishOptions and then retrieve a product code (productId) from the intent
in the called “On Tap Activity”. I would then use this product code to determine what to show to the user in the “On Tap Activity”
It seems calling push notification with template doesnt give me this ability because i have to set the header value ie productId (which i dont know in advance)
in the template itself.Is there something am missing?
Hello, @Nkekere_Tommy_Minimann.
Could you share with me the code where you get information with “Action On Tap”?
Best Regards, Nikita
public class ButtonHandlerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = this.getIntent();
// get button title
final String buttonTitle = intent.getAction();
// get message body
final String messageTag = intent.getStringExtra( PublishOptions.MESSAGE_TAG );
// get message title
final String contentTitleTag = intent.getStringExtra( PublishOptions.ANDROID_CONTENT_TITLE_TAG );
// get message subtext
final String summarySubtext = intent.getStringExtra( PublishOptions.ANDROID_SUMMARY_SUBTEXT_TAG );
// get custom header value - in this example, the name of the header is "productId"
String headerValue = intent.getStringExtra( "productId" );
}
}
Hello @Nkekere_Tommy_Minimann
I’ve created an internal ticket to investigate your issue(BKNDLSS-27250)
We are not sure if the issue is located on our side, but we will inform you when found the root of the issue.