GcmPubSub INVALID_PARAMETERS Exception Exception

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(); // Subscribe to topic channels - subscribeTopics(local_token); + subscribeTopics(token); // You should store a boolean that indicates whether the generated token has been // sent to your server. If the boolean is false, send the token to your server, @@ -120,15 +121,8 @@ // [START subscribe_topics] 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()); - } + GcmPubSub pubSub = GcmPubSub.getInstance(this); + pubSub.subscribe(token, "/topics/" + topic, null); } } // [END subscribe_topics] 

Certainly, I can’t imagine the changes that cause the code to crash. Please, help.

+5
source share

Source: https://habr.com/ru/post/1233532/


All Articles