Andrea php Andrea php - 1 year ago 290
PHP Question

Group key onesignal push notification

created a project on one signal.

I can send to php notification on my phone.

The problem comes when it arrives more than one notification. The new notification replaces the previous notification (not yet read ).

How do you get instead say that Android has 2 unread notifications?

I have try write the same

but the notification never stacked and the newest continue replace the previus.

This is my code:

function sendMessage(){
$content = array(
"en" => 'text message test'

$fields = array(
'app_id' => "XXxxxxXX-xxxxXX-XXxxX-Xxxx-XxxxXXx",
'included_segments' => array('All'),
'data' => array("foo" => "bar"),
'headings' => array("en" => "Test message!!"),
'android_group' => 'TESTGROUP',
'android_group_message' => array("en" => "message"),
'contents' => $content

$fields = json_encode($fields);
print("\nJSON sent:\n");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'));
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

$response = curl_exec($ch);

return $response;

$response = sendMessage();

How can i solve this problem?

Answer Source

android_group used to enable notification stacking only works for Android apps.

If you are you're web push with Chrome for Android the replacement behavior your seeing is expected and isn't configurable. Same behavior on Chrome for Desktop and Firefox.

Also note android_group_message should contain $[notif_count] so the number of unread messages is seen. Example array("en" => "You have $[notif_count] new messages")