I implemented GCM in my application. But some releases back stop receiving messages from gcm. Google reports "InvalidRegistration" when I send a message via an http message.
Research shows that the problem is with subscribeTopics (), which raises INVALID_PARAMETERS in recent releases. Code
RegistrationIntentService.java
private void subscribeTopics(String token) throws IOException { for (String topic : TOPICS) { GcmPubSub pubSub = GcmPubSub.getInstance(RegApp.getContext()); try { Log.i("KK_Reg", "Token to pubsub " + token); pubSub.subscribe(token, "/topics/" + topic, null); Log.i("KK_Reg", "PubSub subscribed"); } catch (java.io.IOException ex) { Log.e("KK_Reg", "Subscribe topics error"); Log.e("KK_Reg", ex.toString()); } } }
The following is a list of differences between working and failed releases:
--- failed release/RegistrationIntentService.java +++ working release/RegistrationIntentService.java @@ -54,7 +54,8 @@ public class RegistrationIntentService extends IntentService { private static final String TAG = "RegIntentService"; - private static final String[] TOPICS = {"ru-konvent-reg-reg-all"}; + private static final Object VTAG = new Object(); + private static final String[] TOPICS = {"all"}; private static final String gcm_reg_url; @@ -85,11 +86,11 @@ Log.i(TAG, "GCM Registration Token: " + token); local_token = token; - RegApp.setGcmToken(local_token); + RegApp.setGcmToken(token); RegApp.sendRegistrationToServer();
Certainly, I canβt imagine the changes that cause the code to crash. Please, help.
source share