当前位置: 首页 > 知识库问答 >
问题:

谷歌云消息-GCM-服务不可用

欧博简
2023-03-14

我正在尝试,为了实施新的GCM,我遵循Google get声明:http://developer.android.com/guide/google/gcm/gs.html

我被困在获取我的设备注册ID!

我的应用程序一直试图与谷歌服务器连接,这里我的错误日志:

onReceive: com.google.android.gcm.intent.RETRY
GCM IntentService class: com.dombox.app.GCMIntentService
Acquiring wakelock
[GCMIntentService] start
Registering app com.dombox.app of senders _my_sender_id_
Releasing wakelock
onReceive: com.google.android.c2dm.intent.REGISTRATION
GCM IntentService class: com.dombox.app.GCMIntentService
Acquiring wakelock
[GCMIntentService] start
handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
Registration error: SERVICE_NOT_AVAILABLE
Scheduling registration retry, backoff = 912617 (768000)
Releasing wakelock

这是我的活动代码,询问身份证:

    try{
        Log.i(TAG, "[checkNotifRegistration] checkDevice");
        GCMRegistrar.checkDevice(this);
        Log.i(TAG, "[checkNotifRegistration] checkManifest");
        GCMRegistrar.checkManifest(this);
        if (GCMRegistrar.isRegistered(this)) {
            Log.i(TAG, "[checkNotifRegistration] reg id : "+GCMRegistrar.getRegistrationId(this));
        }
        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
            // SENDER_ID is my project id into google account url
            GCMRegistrar.register(this, SENDER_ID);
            Log.i(TAG, "[checkNotifRegistration] reg id : "+GCMRegistrar.getRegistrationId(this));
        } else {
            Log.i(TAG, "[checkNotifRegistration] already registered as : " + regId);
        }
    } catch(Exception e){
        Log.e(TAG, "[checkNotifRegistration] Exception : "+e.getMessage());
        e.printStackTrace();
    }

这是我的服务代码

public class GCMIntentService extends GCMBaseIntentService {

private static final String TAG = "GCMIntentService";

public GCMIntentService() {
    super(SENDER_ID);
           // SENDER_ID is my project id into google account url
    // TODO Auto-generated constructor stub
    Log.d(TAG, "[GCMIntentService] start");
}


public GCMIntentService(String senderId) {
    super(senderId);
    // TODO Auto-generated constructor stub
    Log.d(TAG, "[GCMIntentService] start - sender Id : "+senderId);
}
}

这是我的Android清单:

<permission android:name="com.dombox.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.dombox.app.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >

    <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.myapp.app" />
        </intent-filter>
    </receiver>

<service android:name=".GCMIntentService" android:enabled="true"/>

    <activity
        android:name=".activity.Myapp"
        android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

我遵循谷歌的指示,但我坚持这个服务不可用的错误,

我做错了什么?

共有3个答案

云昊阳
2023-03-14

请记住,如果您位于公司防火墙之后,GCM使用的某些端口可能不允许通过本地无线网络进行通信。我最初尝试让模拟器工作时遇到了这个问题。我必须获得一个特殊的IP,允许下面列出的端口通过。

注意:如果您的组织有防火墙限制进出互联网的流量,您需要将其配置为允许与GCM连接,以便您的Android设备接收消息。要打开的端口为:5228、5229和5230。GCM通常仅使用5228,但有时使用5229和5230。GCM不提供特定的IP,因此您应该允许防火墙接受到Google的ASN 15169中列出的IP块中包含的所有IP地址的传出连接。

http://developer.android.com/google/gcm/gcm.html

何越
2023-03-14
android:enabled="true"  

去掉这个^

如果你还没有把这个加到你的清单上

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8"

GCMinentService中不需要第二个构造函数。只有这个

public GCMIntentService() {         
 super(SENDER_ID);  }

确保您的发件人ID是在您浏览google code网站和GCM服务时从浏览器中复制的URL号码。

何升
2023-03-14

问题与代码无关,而是与测试手机的链接有关。测试手机没有SIM卡,且未设置时钟。所以谷歌不能在错误的时间重新注册。

我使用Android虚拟设备、谷歌api和设置测试手机时钟来获得注册Id。

 类似资料:
  • 更新:已弃用GCM,请使用FCM 如何将新的Google云消息集成到PHP后端?

  • 上面写着“Google Cloud Messaging(GCM)是一个免费服务”,但是为了使它能够运行,我需要在Google Cloud平台中创建一个项目,这需要花钱…那怎么免费呢?还是我错过了什么?

  • 我正在尝试用GCM开发一个应用程序。我读了关于GCM的官方文件,但感觉有两种方法可以做到这一点。 似乎有两种方法可以将设备注册到GCM。 "http://developer.android.com/guide/google/gcm/gs.html#android-应用程序“说, 另一方面,“http://developer.android.com/guide/google/gcm/gcm.html

  • 我正在尝试在我的android应用程序中使用GCM服务。 为此,我使用Android留档从http://developer.android.com/guide/google/gcm/gcm.html 我用发送者id等创建了客户端注册过程,并在服务器端应用程序中使用注册id和发送者id发送消息。 当我通过Eclipse在手机中安装应用程序时,推送通知工作正常,因此我的发件人id是正确的。 然后,当我

  • 我正在使用GCM向Android应用程序发送和接收推送通知。我是从这里给出的一个例子中创建这个应用程序的(Android的谷歌云消息GCM和推送通知) 这些是我正在使用的java文件 最终语境=此; shareRegidTask=new AsyncTask() AsyncTask()上出错 通知兼容。Builder mBuilder=new NotificationCompat。建造商( 这).

  • 我正在尝试使用appengine实现GCM。我创建并部署了默认的appengine后端GCM模板。我创建一个GCM注册id: 然后,我使用模板中的默认注册endpoint将这个regID存储在appengine上。我的广播接收器如下所示: 这是我的舱单: BroadCastReceiver和intent服务在我的项目中是独立的类。appengine后端GCM是一个单独的模块。创建此模块期间: 编译