This is what the linked documentation says:
// if retrieving in a button handling activity:
Intent intent = this.getIntent();
String headerValue = intent.getStringExtra( “sample_header_name” );
However, I don’t have buttons on my notifications and use them to launch the app when the user taps the notification itself. The intent of the main activity that is launched has no extras. So I don’t know how to obtain the notification info in this use case.
Hi, Milen.
For now we can only advise to construct a template (based on your message data) and retrieve headers from it.
You no need to use buttons in templates to get your headers. They will be available just in the intent, that comes into activity handler on a tap.
I don’t use a template because I need to customize the notification from code and as far as I know you cannot customize templates.
The two specific things I need are:
Deliver notification to particular devices that are determined dynamically in code
Add custom header information that is also dynamic
(I know about Smart Text but it doesn’t achieve the job in this case as the info is not directly related to the user, receiving the notification)
Any suggestion on how I can retrieve custom header information in Android while achieving the above two requirements? I can successfully do this in iOS but not in Android.
I believe for now getting header values is available only from Intent if notification was sent from a template. I’ve scheduled a task to add a feature for extracting header values in Android for the rest of the cases. We’ll notify you as soon the task is complete. I think it’s a matter of 1-2 weeks
I ran into a problem - if the app receives several notifications the custom headers from the first one remain unchanged even after the other notifications are received.
Steps to reproduce:
Send a notification with “custom_header” = “1”
Open notification (main activity is launched)
From the main activity obtain the value of “custom_header” (it is correctly “1”)
Minimize app
Send another notification with “custom_header” = “2”
Open notification (main activity is again launched)
From the main activity obtain the value of “custom_header”
Expected result:
“custom_header” now has a value of “2”
Actual result:
“custom_header” is still “1”
Am I missing something or is this a bug with the SDK?
Yes, I found this while debugging why the app kept focusing the item from the first notification. The problem is indeed that getIntent().getStringExtra("custom_header") returns the value from the first notification.
Just tried restarting the app and curiously enough the behaviour remains the same!
I’ve tried changing values of custom headers on push notification publishing and everything worked fine in my case. What I did:
In onMessage() of my custom PushService class (which extends BackendlessFCMService) getting the header as followed: final String customHeader = intent.getStringExtra("customHeader");
Tried sending a message via console (Messaging tab > Messages screen) and via Android SDK v 5.2.5
Then simply printing header’s value to logcat.
Log.i(“HEADER”, customHeader);
Every message that was sent has different value for custom header, and the result proofs that SDK itself correctly handles this
I don’t use a custom PushService. I just obtain the header from the extras of the launched Activity's Intent: getIntent().getStringExtra(Signal.KEY_SIGNAL_ID)