gcm返回服务不可用

时间:2014-03-22 22:22:13

标签: java android android-asynctask google-cloud-messaging

我有这个代码。我从Google控制台输入项目密钥作为snederId并收到错误: 服务不可用。

您建议我在设置注册码时仔细检查哪些步骤?

private void registerInBackground() {
        new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... params) {
                String msg = "";
                try {
                    if (gcm == null) {
                        gcm = GoogleCloudMessaging.getInstance(context);
                    }
                    regId = gcm.register(SENDER_ID);
                    msg = "Device registered, registration ID=" + regId;

                    // You should send the registration ID to your server over
                    // HTTP, so it
                    // can use GCM/HTTP or CCS to send messages to your app.
                    sendRegistrationIdToBackend();

                    saveRegIdToDb();

                    // For this demo: we don't need to send it because the
                    // device will send
                    // upstream messages to a server that echo back the message
                    // using the
                    // 'from' address in the message.

                    // Persist the regID - no need to register again.
                    storeRegistrationId(context, regId);
                } catch (IOException ex) {
                    msg = "Error :" + ex.getMessage();
                    // If there is an error, don't just keep trying to register.
                    // Require the user to click a button again, or perform
                    // exponential back-off.
                }
                return msg;
            }

            @Override
            protected void onPostExecute(String msg) {
                // mDisplay.append(msg + "\n");
            }
        }.execute(null, null, null);
    }

2 个答案:

答案 0 :(得分:0)

一些基本检查:

  • 您的项目是否已被Google列入白名单?
  • 您使用正确的sender_id(项目编号)吗?
  • 网络连接正常吗?
  • 是否安装了Google Play服务并保持最新状态?

上述检查之一不应该没问题。

答案 1 :(得分:0)

检查发件人ID,这是项目编号 enter image description here

并启用“API&amp; auth” - &gt; “Google Cloud Messaging for Android”

相关问题