【问题标题】:Firebase cloud messaging message id shows but not receiving notificationsFirebase 云消息消息 ID 显示但未收到通知
【发布时间】:2017-06-07 10:36:20
【问题描述】:

我能够获得消息 ID 作为回报,但通知未显示在 android 设备中,但从 firebase 控制台运行良好,我可以从 firebase 控制台发送到主题“nadakko”

     <?php
 $data = array(
           "message" => "sfsdgdgdfg"
          );
  $final = array(
            "condition" => "'nadakko' in topics",
            "data" => $data
           );

  $url = 'https://fcm.googleapis.com/fcm/send';

  $headers = array(
              'Authorization: key=AIzaSyAkjY4wwambC7ryNxr-KEjsx4VgSZuh-UY',
              'Content-Type: application/json'
             );
  // Open connection
  $ch = curl_init();

  // 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($final));
  // Execute post
  $result = curl_exec($ch);

  if ($result === FALSE) {
      // curl failed
      echo "Faild";
  }
echo $result;
  // Close connection
  curl_close($ch);
  ?>

发送消息后,我从 android 监视器收到此错误消息已接收到移动设备,但存在一些问题

06-07 18:06:16.139 8802-12118/info.***.*** E/MyFirebaseMessagingService: Data Payload: {message=sfsdgdgdfg}
06-07 18:06:16.139 8802-12118/info.**.**** E/MyFirebaseMessagingService: push json: {"message":"sfsdgdgdfg"}
06-07 18:06:16.139 8802-12118/info.**.*** E/MyFirebaseMessagingService: Json Exception: No value for data

【问题讨论】:

    标签: android firebase firebase-cloud-messaging


    【解决方案1】:
    06-07 18:06:16.139 8802-12118/info.**.*** E/MyFirebaseMessagingService: Json Exception: No value for data
    

    这是问题所在,您需要阅读message 而不是data 使用所以它将是

    String message = json.getString("message");

    【讨论】:

    • 更改后我得到这个“Json Exception: Value sfsdgdgdfg at message of type java.lang.String cannot be convert to JSONObject”
    • 让我检查一下
    • 新的 errorJson 异常:java.lang.String 类型的消息中的值 sfsdgdgdfg 无法转换为 JSONObject
    • 你能帮帮我吗
    【解决方案2】:
    JSONObject data = json.getJSONObject("data");
    String title = data.getString("title");
    String message = data.getString("message");
    

    【讨论】:

      猜你喜欢
      • 2017-12-24
      • 1970-01-01
      • 2018-03-13
      • 1970-01-01
      • 2016-09-17
      • 2021-11-20
      • 2018-09-13
      • 1970-01-01
      • 2020-07-28
      相关资源
      最近更新 更多