duanqiang9212 2016-09-06 14:29
浏览 346

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

I have read much documents regarding firebase push notification behaviour clearly. I'm able to see notification on the system tray when my app is in background but not triggering onMessageReceivedcall back when app is in foreground. I can see the logs that the message is received on my app. I have tried calling with data payload and without data payload from app server. My app server is using php script to trigger the fcm apis. Following is the php script I'm using

  $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);

Following are the services i'm using in my Android app

    <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条回答 默认 最新

  • douqi3064 2017-02-05 15:47
    关注

    I had the same problem. My problem was that the <service></service> tags were outside the <application></application> tag in the manifest file. When I put in the <application></application> tag, the problem was solved.

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题