Android GcmPubSub无效_参数异常

Android GcmPubSub无效_参数异常,android,google-cloud-messaging,Android,Google Cloud Messaging,我已经在我的应用程序中实现了GCM。但在某些版本之前,它停止接收来自gcm的消息。当我通过http post发送消息时,谷歌说“InvalidRegistration” 调查显示,问题出在subscribeTopics()中,它在最新版本中引发了无效的_参数。代码是 RegistrationEntertService.java private void subscribeTopics(String token) throws IOException { for (String topic

我已经在我的应用程序中实现了GCM。但在某些版本之前,它停止接收来自gcm的消息。当我通过http post发送消息时,谷歌说“InvalidRegistration”

调查显示,问题出在subscribeTopics()中,它在最新版本中引发了无效的_参数。代码是

RegistrationEntertService.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());
        }
    }
}
工作版本和失败版本之间的差异如下所示:

--- 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]

当然,我无法想象更改会导致代码失败。请提供帮助。

无效的\u参数可能是由错误的令牌、错误的主题格式(主题中的空格)或使用旧的gcm.register方法获取令牌造成的。你能确认这些不是问题吗?是的,我能。问题出在
local\u-token
中,但我不明白为什么-在我消除了var之后,我想一切都很好。我不确定为什么要使用local\u-token和token,但在订阅之前似乎有什么东西在改变local\u-token或token。我要再次检查RegApp.setGcmToken是否没有更改令牌的值。它不应该,因为我假设
public static void setGcmToken(字符串令牌){should\u send\u gcm=true;gcmToken=token;}
如果它在没有附加var的情况下工作,那么GCM也不是问题。我建议检查您传递的值。