Alexei
Alexei

Reputation: 15726

Not receive push notifications: com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 400

In my android app I success use GCM to get push notification. Here snippet that send push notification:

import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;

public class GcmWrapper {
    private static AtomicReference<Sender> gcmSender;


    private void toGCM(String receiver, String payload) {
        String status;
        Message message = new Message.Builder().addData("data", payload).build();
        Result result;
        try {
            result = gcmSender.get().send(message, receiver, 5);
            status = "Sent message to one device: " + result;
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }

    }
}

And this code work success many years. Nice.

But from summer 2019 I get error in this line:

result = gcmSender.get().send(message, receiver, 5); // line number 41

error message:

[ERROR] 29.08.2019 15:09:27.835 [Thread-7271] [ticket = ] [request_id = ] com.myproject.service.notify.GcmWrapper.toGCM(GcmWrapper.java:52) 
    HTTP Status Code: 400
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 400
        at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
        at com.google.android.gcm.server.Sender.send(Sender.java:121)
        at com.myproject.service.notify.GcmWrapper.toGCM(GcmWrapper.java:41)
        at com.myproject.service.notify.GcmWrapper.access$000(GcmWrapper.java:14)
        at com.myproject.service.notify.GcmWrapper$1.run(GcmWrapper.java:28)
at java.lang.Thread.run(Thread.java:722)

And as result android clients not receive push notifications.

Upvotes: 1

Views: 870

Answers (1)

Christophe Maillot
Christophe Maillot

Reputation: 313

GCM is deprecated and has been replace with FCM. GCM should not be used anymore. There have been a lot of mails / communication about this.

See https://developers.google.com/cloud-messaging/faq for instance.

Upvotes: 1

Related Questions