title: Successful HTTP POST 200 to FCM but no notification on Android app
body: <p>This small program written in Java should send a notification to my android app through firebase cloud messaging. Currently, the connection with FCM seems successful according to the limited response code I receive (200, OK). However, no notification is received on the Android app.</p>
  
  <p>When using another 3rd party java app for the same server key the notification is delivered successfully on the same Android application, in this case it is not.</p>
  
  <p>I think the problem lies in the device token part, I don't need to send the notification to a specific device, I want the notification to be sent to all/any available device as long as it reaches my device.</p>
  
  <pre><code>import java.io.OutputStream;
  import java.net.HttpURLConnection;
  import java.net.URL;
  
  public class AndroidPush {
  
      /**
       * Replace SERVER_KEY with your SERVER_KEY generated from FCM
       * Replace DEVICE_TOKEN with your DEVICE_TOKEN
       */
      private static String SERVER_KEY = "AAA*******APA91bH2i5FGIhBhMj3YEf0yCq*********************************************************************";
      private static String DEVICE_TOKEN = "caNraerHp9M:APA91bEKyYHV9ymsFh4xXyii****************";
  
  
      /**
       * USE THIS METHOD to send push notification
       */
      public static void main(String[] args) throws Exception {
          String title = "My First Notification";
          String message = "Hello, I'm push notification";
          sendPushNotification(title, message);
      }
  
  
      /**
       * Sends notification to mobile
       */
      private static void sendPushNotification(String title, String message) throws Exception {
          String pushMessage = "{\"data\":{\"title\":\"" +
                  title +
                  "\",\"message\":\"" +
                  message +
                  "\"},\"to\":\"" +
                  DEVICE_TOKEN +
                  "\"}";
          // Create connection to send FCM Message request.
          URL url = new URL("https://fcm.googleapis.com/fcm/send");
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setRequestProperty("Authorization", "key=" + SERVER_KEY);
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestMethod("POST");
          conn.setDoOutput(true);
  
          // Send FCM message content.
          OutputStream outputStream = conn.getOutputStream();
          outputStream.write(pushMessage.getBytes());
  
          System.out.println(conn.getResponseCode());
          System.out.println(conn.getResponseMessage());
      }
  }
  </code></pre>
  
  <p><strong>RESPONSE CODE:
  200
  OK</strong></p>
  
  <p><strong>ANDROID APPLICATION</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      // defining the constant for the tag in onTokenRefresh
      private static final String TAG = "TFA_service";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          onTokenRefresh();
          //get all server-FCM-Android notifications
          FirebaseMessaging.getInstance().subscribeToTopic("ALL");
  
      }
  
      public void onTokenRefresh() {
          // Get updated InstanceID token.
          String refreshedToken = FirebaseInstanceId.getInstance().getToken();
          Toast.makeText(this, refreshedToken, Toast.LENGTH_SHORT).show();
          Log.d(TAG, "Refreshed token: " + refreshedToken);
          System.out.println(refreshedToken);
  
          // TODO: Implement this method to send any registration to your app's servers.
          System.out.println("Registration.onTokenRefresh TOKEN: " + refreshedToken );
      }
  </code></pre>