gpt4 book ai didi

php - 应用程序在前台时不调用 Firebase onMessageReceived

转载 作者:行者123 更新时间:2023-11-29 15:41:33 26 4
gpt4 key购买 nike

我已经清楚地阅读了很多关于 firebase 推送通知行为的文档。当我的应用程序处于后台时,我可以在系统托盘上看到通知,但当应用程序处于前台时,我不会触发 onMessageReceived 回调。我可以看到在我的应用程序上收到消息的日志。我试过使用数据有效负载和没有来自应用程序服务器的数据有效负载进行调用。我的应用程序服务器正在使用 php 脚本来触发 fcm api。以下是我正在使用的 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>

最佳答案

我遇到了同样的问题。我的问题是 <service></service>标签在 <application></application> 之外 list 文件中的标记。当我输入 <application></application>标签,问题解决。

关于php - 应用程序在前台时不调用 Firebase onMessageReceived,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39351559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com