I am using gcm to push notifications to one or multiple devices, However I constantly get the error message: "mismatched sender ID".
Here is my code:
public static void post(String apiKey){
    try{
        // prepare JSON
        JSONObject jGcmData = new JSONObject();
        JSONObject jData = new JSONObject();
        jData.put("message", "{good luck}");
        jGcmData.put("to","token ID");
        jGcmData.put("data", jData);
        // Create connection to send GCM Message request.
        URL url = new URL("https://android.googleapis.com/gcm/send");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Authorization", "key=" + apiKey);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        // Send GCM message content.
        OutputStream outputStream = conn.getOutputStream();
        outputStream.write(jGcmData.toString().getBytes());
        // Read GCM response.
        InputStream inputStream = conn.getInputStream();
        String resp = IOUtils.toString(inputStream);
        System.out.println(resp);
    } catch (IOException e) {
        System.out.println("Unable to send GCM message. "+e);
    }
}
Also, when I used jGcmData.put("to","/topics/foo-bar");instead of jGcmData.put("to","token ID");, the notification can be sent successfully. However what I want is to push notification to selected devices.