<tfoot id='FCrlS'></tfoot>
    • <bdo id='FCrlS'></bdo><ul id='FCrlS'></ul>

  • <small id='FCrlS'></small><noframes id='FCrlS'>

  • <i id='FCrlS'><tr id='FCrlS'><dt id='FCrlS'><q id='FCrlS'><span id='FCrlS'><b id='FCrlS'><form id='FCrlS'><ins id='FCrlS'></ins><ul id='FCrlS'></ul><sub id='FCrlS'></sub></form><legend id='FCrlS'></legend><bdo id='FCrlS'><pre id='FCrlS'><center id='FCrlS'></center></pre></bdo></b><th id='FCrlS'></th></span></q></dt></tr></i><div id='FCrlS'><tfoot id='FCrlS'></tfoot><dl id='FCrlS'><fieldset id='FCrlS'></fieldset></dl></div>

        <legend id='FCrlS'><style id='FCrlS'><dir id='FCrlS'><q id='FCrlS'></q></dir></style></legend>

        从服务器端向安卓设备发送 FCM 消息

        时间:2024-08-22

          <small id='T3fJv'></small><noframes id='T3fJv'>

          <i id='T3fJv'><tr id='T3fJv'><dt id='T3fJv'><q id='T3fJv'><span id='T3fJv'><b id='T3fJv'><form id='T3fJv'><ins id='T3fJv'></ins><ul id='T3fJv'></ul><sub id='T3fJv'></sub></form><legend id='T3fJv'></legend><bdo id='T3fJv'><pre id='T3fJv'><center id='T3fJv'></center></pre></bdo></b><th id='T3fJv'></th></span></q></dt></tr></i><div id='T3fJv'><tfoot id='T3fJv'></tfoot><dl id='T3fJv'><fieldset id='T3fJv'></fieldset></dl></div>
            <legend id='T3fJv'><style id='T3fJv'><dir id='T3fJv'><q id='T3fJv'></q></dir></style></legend>
              <bdo id='T3fJv'></bdo><ul id='T3fJv'></ul>

                  <tbody id='T3fJv'></tbody>
                <tfoot id='T3fJv'></tfoot>
                • 本文介绍了从服务器端向安卓设备发送 FCM 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  随着新的更新,现在将使用 FCM.

                  With the new update, FCM is now going to be used.

                  我尝试了 git 中的示例应用程序,它运行良好.我可以从控制台发送通知.

                  I tried the sample app from git and it's working all fine. I can send notifications from the console.

                  但我想在某个事件触发后从服务器发送通知.我采用了与 GCM 中相同的方法,但它不起作用.

                  But I want to send the notification from the server after a certain event is triggered. I followed the same approach like in GCM but it's not working.

                  05-20 20:40:58.941 30132-30919/com.google.firebase.quickstart.fcm E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
                                                                                                      Process: com.google.firebase.quickstart.fcm, PID: 30132
                                                                                                      java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.messaging.RemoteMessage$Notification.getBody()' on a null object reference
                                                                                                          at com.google.firebase.quickstart.fcm.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:53)
                                                                                                          at com.google.firebase.messaging.FirebaseMessagingService.zzo(Unknown Source)
                                                                                                          at com.google.firebase.messaging.FirebaseMessagingService.zzn(Unknown Source)
                                                                                                          at com.google.firebase.messaging.FirebaseMessagingService.zzm(Unknown Source)
                                                                                                          at com.google.firebase.iid.zzb$2.run(Unknown Source)
                                                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                                          at java.lang.Thread.run(Thread.java:818)
                  05-20 20:40:59.118 30132-30279/com.google.firebase.quickstart.fcm E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb9e83390
                  

                  我正在关注这个 PHP 脚本 来发送通知.如果我尝试执行脚本,我会得到以下结果.

                  Am following this PHP Script to send the notification. If I try to execute the script, I get the following result.

                  {"multicast_id":4679427854122301046,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1463757518309261%31bd1c96f9fd7ecd"}]}
                  

                  注意:我浏览了他们的 docs 并将代码修改为只有正文和标题.即使那样它也不起作用.

                  NOTE : I went through their docs and modified the code is gist to have only body and title. Even then it's not working.

                  推荐答案

                  你可以使用这个完整的代码

                  You can use this complete code

                  <?php
                  
                  function sendFCM($mess,$id) {
                  $url = 'https://fcm.googleapis.com/fcm/send';
                  $fields = array (
                          'to' => $id,
                          'notification' => array (
                                  "body" => $mess,
                                  "title" => "Title",
                                  "icon" => "myicon"
                          )
                  );
                  $fields = json_encode ( $fields );
                  $headers = array (
                          'Authorization: key=' . "AIzaSyA9vpL9OuX6moOYw-4n3YTSXpoSGQVGnyM",
                          'Content-Type: application/json'
                  );
                  
                  $ch = curl_init ();
                  curl_setopt ( $ch, CURLOPT_URL, $url );
                  curl_setopt ( $ch, CURLOPT_POST, true );
                  curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
                  curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
                  curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
                  
                  $result = curl_exec ( $ch );
                  curl_close ( $ch );
                  }
                  
                  ?>
                  

                  将消息和令牌 ID 作为参数传递给 sendFCM($mess,$id) 调用.

                  Pass message and token id as a parameter to the sendFCM($mess,$id) call.

                  这篇关于从服务器端向安卓设备发送 FCM 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Pushnotification 服务器端实现 下一篇:当授权密钥是我的服务器密钥时的 Firebase MismatchSenderID

                  相关文章

                  <legend id='GjrCr'><style id='GjrCr'><dir id='GjrCr'><q id='GjrCr'></q></dir></style></legend>

                    <i id='GjrCr'><tr id='GjrCr'><dt id='GjrCr'><q id='GjrCr'><span id='GjrCr'><b id='GjrCr'><form id='GjrCr'><ins id='GjrCr'></ins><ul id='GjrCr'></ul><sub id='GjrCr'></sub></form><legend id='GjrCr'></legend><bdo id='GjrCr'><pre id='GjrCr'><center id='GjrCr'></center></pre></bdo></b><th id='GjrCr'></th></span></q></dt></tr></i><div id='GjrCr'><tfoot id='GjrCr'></tfoot><dl id='GjrCr'><fieldset id='GjrCr'></fieldset></dl></div>
                      <bdo id='GjrCr'></bdo><ul id='GjrCr'></ul>
                    1. <tfoot id='GjrCr'></tfoot>

                      <small id='GjrCr'></small><noframes id='GjrCr'>