2016-12-12 17 views
0

コンソールを使用してAndroidアプリケーションでプッシュ通知を送信できます。サーバー側のコードを使用すると、正常にメッセージを送信する通知が表示されますが、実際には通知はデバイス側で受信できません。 { "multicast_id":私はリターンで応答を得たアンドロイドデバイスでFCMを使用したプッシュ通知の送信

public static string SendPushNotification() { 
     try { 
      string applicationID = "AAAA4GkXVHA:....-qRw"; 

      string senderId = "963..28"; 

      string deviceId = "APA91bHLV...IC4s"; 

      WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); 
      tRequest.Method = "post"; 
      tRequest.ContentType = "application/json"; 
      var data = new { 
       to = deviceId, 
       notification = new { 
        body = "hema", 
        title = "hem", 
        //priority = "normal", 
        //sound = "Enabled" 
       }, 
      }; 

      var serializer = new JavaScriptSerializer(); 
      var json = serializer.Serialize(data); 
      Byte[] byteArray = Encoding.UTF8.GetBytes(json); 
      tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); 
      tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 
      tRequest.ContentLength = byteArray.Length; 
      using (Stream dataStream = tRequest.GetRequestStream()) { 
       dataStream.Write(byteArray, 0, byteArray.Length); 
       using (WebResponse tResponse = tRequest.GetResponse()) { 
        using (Stream dataStreamResponse = tResponse.GetResponseStream()) { 
         using (StreamReader tReader = new StreamReader(dataStreamResponse)) { 
          String sResponseFromServer = tReader.ReadToEnd(); 
          string str = sResponseFromServer; 
          return str; 
         } 
        } 
       } 
      } 
     } 
     catch (Exception ex) { 
      string str = ex.Message; 
      return str; 
     } 
    } 

次のとおりです。、私のコードが間違っているものを私に教えてください8288766196764532656、 "成功":1、 "失敗":0、」 canonical_ids ":0、" 結果 ":[{" MESSAGE_ID ":" 0:1481612825945796%の6ad79a87f9fd7ecd "}]適切なフォーマットでJSONを送信}

答えて

0

{ 
    "to" : "APA91bHLV__P6Qer8U70j82blZt0VdDgc2zo_4DtAD4_MtE-......", 
    "notification" : { 
    "body" : "Success!", 
    "title" : "Hema", 
    "icon" : "myicon" 
    } 
} 

適切にそれをチェックするために、次のことができまた、郵便配達員を使用してください: Postman testing FCM server to device(ios or android)

関連する問題