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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料