Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌云消息-GCM-服务不可用_Android_Google Cloud Messaging_Service Not Available - Fatal编程技术网

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

Android 谷歌云消息-GCM-服务不可用,android,google-cloud-messaging,service-not-available,Android,Google Cloud Messaging,Service Not Available,我正在尝试,为了实施新的GCM,我遵循Google get声明: 我被困在获取我的设备注册ID 我的应用程序一直在尝试连接Google server,下面是我的错误日志: onReceive: com.google.android.gcm.intent.RETRY GCM IntentService class: com.dombox.app.GCMIntentService Acquiring wakelock [GCMIntentService] start Registering app

我正在尝试,为了实施新的GCM,我遵循Google get声明:

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

我的应用程序一直在尝试连接Google server,下面是我的错误日志:

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>

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

我做错了什么

android:enabled="true"  
去掉这个^

如果您还没有将此添加到您的清单中

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

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

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


我使用Android虚拟设备和google api,通过设置测试电话时钟,获得了注册Id。我遇到了这个问题……我的解决方案是禁用互联网连接并使用电话服务。

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


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


我遇到了这个问题,它是由WIFI连接引起的。我关闭了WIFI并再次进行了测试(在3g上),测试成功了。然后我重新打开WIFI,再次出现错误。为了确保这一点,回到3g,它又开始工作了


总之,问题是由连接引起的。

我在genymotion上运行应用程序时遇到了这个问题。按照上面所说的安装google play服务,一切正常。

请小心我发布的TargetSDK版本。当您在新的SDKI上运行时,它可能会影响布局并引发可能的异常。请将my
目标API级别设置为8,并将my
设置为8。但我仍然需要一项不可用的服务error@Tommecpe刚刚解决了服务不可用的问题。如果收到注册码,请检查目录,如果没有,请重新启动设备,然后重试。这为我解决了问题。您的XML标记一定是我被您的评论弄糊涂了。问题与代码无关,但链接到测试电话中使用的谷歌帐户,或者测试电话本身。我使用Android虚拟设备和GoogleAPI获得注册Id。感谢您的帮助我在已知的工作代码中也遇到了同样的问题,这是由于时间设置不正确造成的。您是否遇到过这种情况?该应用程序过去在我的虚拟机(谷歌api)中运行平稳,但现在它停留在服务不可用-重试周期。你的avd上的android版本是什么?我使用的是三星S2手机,错误获取服务不可用。请帮助。@Tommepe您能将此设置为已接受的答案吗?因为这对你和我都有帮助。使用3G平板电脑而不是Wifi连接对我也有帮助。谢谢
public GCMIntentService() {         
 super(SENDER_ID);  }