Skip to content

Data Message can't receive #39

Closed
Closed
@Sakura777

Description

@Sakura777

Unity 5.4.4f1
SO-02E Android 4.4.2

I have built quickstart project and can receive Notification correctly.
But Data Messages sent from PHP can't receive.

<?php

$api_key  = "MY_KEY";
$base_url = "https://fcm.googleapis.com/fcm/send";


//Data Message : It can't receive
$data = array(
    "to"           => "DEVICE_ID",
    "priority"     => "high",
    "data"         => array(
        "message"   => "Message"
    )
);

/*
//notification : It can receive
$data = array(
     "to"           => "DEVICE_ID",
     "priority"     => "high",
     "notification" => array(
        "title" => "title",
        "body"  => "body"
    )
);
*/
$header = array(
     "Content-Type:application/json",
     "Authorization:key=".$api_key
);
$context = stream_context_create(array(
    "http" => array(
         'method' => 'POST',
         'header' => implode("\r\n",$header),
         'content'=> json_encode($data)
    )
));

echo file_get_contents($base_url,false,$context);

Same message is returned for both Data Message and Notification in echo.
(Even Data Message returns "success":1 )
{"multicast_id":~~~,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"~~~"}]}

But on device,
Notification : Messages appear in the notification list.
Data Message : Messages are not displayed anywhere.

By the way, when sending by inputting detailed options from Firebase Console,
messages appear in the notification list.

I think there is a problem with the data setting method, but I do not know where it is.
Could you just tell us what you think is the cause?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions