谷歌云消息传递 - GCM - SERVICE_NOT_AVAILABLE [英] Google Cloud Messaging - GCM - SERVICE_NOT_AVAILABLE

查看:598
本文介绍了谷歌云消息传递 - GCM - SERVICE_NOT_AVAILABLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,实施新的GCM,我下面谷歌的获取说的: <一href="http://developer.android.com/guide/google/gcm/gs.html">http://developer.android.com/guide/google/gcm/gs.html

I am trying, to implement the new GCM, I am following Google get stated : http://developer.android.com/guide/google/gcm/gs.html

我被陷在得到我的设备注册ID!

I getting stuck at getting my device registration ID !

我的应用程序不断尝试与谷歌的服务器连接,在这里,我的错误日志:

My app keep trying to connect with Google server, Here my error logs :

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

下面是我的活动code,要求一个ID:

Here is my Activity Code, asking for an 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();
    }

下面我服务code

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);
}
}

和这里是我的Andr​​oid清单:

And here is my Android Manifest :

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

我下面谷歌的指示,但我还是坚持了这个SERVICE_NOT_AVAILABLE错误,

I'm following Google's instruction, but I stuck with this SERVICE_NOT_AVAILABLE error,

我是什么做错了吗?

推荐答案

这个问题是不是code相关,但链接到测试手机。 测试手机没有SIM卡,并且时钟没有设置。因此谷歌无法与一个错误的时间resgistred吧。

The problem was not code related, but link to the test phone. The test phone do not have a SIM, and the clock was not set. So google cannot resgistred it with a wrong time.

我管理有使用Android的虚拟设备,与谷歌API的一个注册ID,并通过设置测试手机时钟

I manage to have a registration Id using a Android Virtual Device, with google api, and by setting the test phone clock.

这篇关于谷歌云消息传递 - GCM - SERVICE_NOT_AVAILABLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆