当应用程序处于前台时,Firebase onMessageReceived未被调用

时间:2016-09-06 14:29:10

标签: php android firebase firebase-cloud-messaging

我已经清楚地阅读了很多关于firebase推送通知行为的文档。当我的应用处于后台时,我能够在系统托盘上看到通知,但是当应用处于前台时,我无法触发onMessageReceived回拨。我可以看到我的应用程序收到消息的日志。我尝试使用数据有效负载进行调用,并且没有来自应用服我的app服务器使用php脚本来触发fcm apis。以下是我使用

的PHP脚本
  $url = 'https://fcm.googleapis.com/fcm/send';
  $fields = array(
            'registration_ids' => $registatoin_ids,
     'notification' => array( "title"=>$title, "body" => $notification_message ,"click_action"  => $click_action,'color' => "#74BCEE",'icon' => "school_logo"));
      $headers = array(
            'Authorization: key='xxxxxxxxx',
            'Content-Type: application/json'
        );

        // Open connection
        $ch = curl_init();

        //echo "here";exit;
        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        // Execute post
        $result = curl_exec($ch);
        if ($result === FALSE) {
            //die('Curl failed: ' . curl_error($ch));
            curl_close($ch);
            return;

        }
        print_r($result);

以下是我在Android应用中使用的服务

    <service
    android:name="service.MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

<service
    android:name="service.MyFirebaseInstanceIdService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题。我的问题是<service></service> 标签位于清单文件中的<application></application>标记之外。当我输入<application></application>标签时,问题就解决了。

相关问题