2016-08-07 7 views
2

私はこのトピックを前に、 で議論しましたが、同じシナリオではないと思います。 FCM(Firebase Cloud Messaging)を介して他のすべてのデバイスにプッシュ通知を送信しようとしています(管理デバイスになる)。 私はトピックを購読しようとしましたが、「MissingRegistration」という同じエラーが発生してもシンプルに保ちました。Firebase FCMプッシュ、エラーが発生しました。 Android

String jsonData = "{\"to\":\"/topics/news\",\"notification\":{\"title\":\"title\",\"body\":\"text\" }}"; 
       byte[] postData = jsonData.getBytes(Charset.forName("UTF-8")); 
       int postDataLength = postData.length; 

       URL url = new URL("https://fcm.googleapis.com/fcm/send"); 
       HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
       con.setDoInput(true); 
       con.setDoOutput(true); 
       con.setInstanceFollowRedirects(true); 
       con.setRequestMethod("POST"); 

       con.setRequestProperty("Content-Type","application/json"); 
       con.setRequestProperty("Authorization","key=AIzaSyB70J***-z34q2_h*******qjZsM5zBIf8Y"); //I've added stars :-) 
       con.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
       con.setRequestProperty("Content-Type","charset=UTF-8"); 
       con.setRequestProperty("Content-Length",Integer.toString(postDataLength)); 

       con.setUseCaches(false); 

       DataOutputStream wr = new DataOutputStream(con.getOutputStream()); 
       wr.write(postData); 

       InputStream inputStream= con.getInputStream(); 
       BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 
       String line = null; 
       String outPut = ""; 
       while (((line = reader.readLine()) != null)){ 
        outPut += line; 
       } 

答えて

7

私も同じエラーを得たが、鉱山は、サーバー側(Androidにレールからのプッシュ)にあったが、私の問題は、私は(私はRestClientを使用していますヘッダにコンテンツタイプを指定するのを忘れていたことでしたfirebaseに投稿する)。それは とにかく私のコードが動作するようになりまし誰か

RestClient.post("https://fcm.googleapis.com/fcm/send", 
      {:to => reg_id,:notification => options }.to_json,{:content_type => :json, :accept => :json,:Authorization => "key=*****"} 
1

は、あなたの答えを投稿いただきありがとうございます、 は私がしなければならなかったすべては、コンテンツタイプを変更で役立つかもしれないホープ(私はちょうどfirebaseドキュメントからコンテンツタイプをコピーしました)。それをサブスクライブトピック....に送ってください。 今、私のすべてのユーザーは私のデバイスから通知を受け取ることができます:-)。

関連する問題