android - Google 云消息传递 - GCM - SERVICE_NOT_AVAILABLE

标签 android google-cloud-messaging service-not-available

我正在尝试实现新的 GCM,我正在关注 Google get statement: http://developer.android.com/guide/google/gcm/gs.html

我在获取我的设备注册 ID 时遇到了困难!

我的应用不断尝试与 Google 服务器连接,这是我的错误日志:

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

这是我的 Activity 代码,要求提供 ID:

    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 list :

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

我按照 Google 的说明进行操作,但遇到了这个 SERVICE_NOT_AVAILABLE 错误,

我做错了什么?

最佳答案

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

我设法通过使用 Android 虚拟设备、使用 google api 并通过设置测试手机时钟获得了一个注册 ID。

关于android - Google 云消息传递 - GCM - SERVICE_NOT_AVAILABLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11398470/

相关文章:

azure - Azure(美国西部)何时支持小型 VM 网站?

java - 使用 c2dm 时出现 SERVICE_NOT_AVAILABLE 错误

google-app-engine - 如何为 Chrome 扩展设置 App Engine 后端?

android - 解析推送 - 如何在 Android 上接收推送时自动打开 Activity 而无需用户操作

javascript - Android 上 JavaScript 中的触摸事件

java - 将文本从字符串设置为十进制格式

ios - 如何通过 GCM 向 iOS 设备发送推送通知?

android - Android 2.2 上的 GCM SERVICE_NOT_AVAILABLE

Java Firestore Android 在查询中使用数组列表来显示来自关注用户的帖子

android - appcompat-v7 : Android HelloWorld App Error