Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.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 GoogleCloudMessaging.register(…)方法始终返回服务\u不可用_Android_Push Notification_Google Cloud Messaging - Fatal编程技术网

Android GoogleCloudMessaging.register(…)方法始终返回服务\u不可用

Android GoogleCloudMessaging.register(…)方法始终返回服务\u不可用,android,push-notification,google-cloud-messaging,Android,Push Notification,Google Cloud Messaging,我正在尝试为我的应用程序实现推送通知。首先,我使用了旧的/非种族歧视的Demoactivity示例,成功地从服务器接收到应用程序的消息 由于它已被弃用,我尝试使用新的GCMAPI来实现相同的Push Notif。服务在这个实现过程中,我主要使用这里提供的代码 http://developer.android.com/google/gcm/gs.html 在我的代码中,每次我尝试将我的设备注册到GCM时,我都会收到“服务不可用”错误。我用于注册的方法就是文档中的smae(如上链接) 私有

我正在尝试为我的应用程序实现推送通知。首先,我使用了旧的/非种族歧视的Demoactivity示例,成功地从服务器接收到应用程序的消息

由于它已被弃用,我尝试使用新的GCMAPI来实现相同的Push Notif。服务在这个实现过程中,我主要使用这里提供的代码

   http://developer.android.com/google/gcm/gs.html
在我的代码中,每次我尝试将我的设备注册到GCM时,我都会收到“服务不可用”错误。我用于注册的方法就是文档中的smae(如上链接)

私有无效寄存器background(){

newasynctask(){
@凌驾
受保护的字符串doInBackground(无效…对象){
字符串msg=“”;
试一试{
如果(gcm==null){
gcm=GoogleCloudMessaging.getInstance(上下文);
}                  
regid=gcm.register(genericputilities.SENDER\u ID);
msg=“设备已注册,注册id=“+regid;
//您应该通过HTTP将注册ID发送到服务器,
//因此,它可以使用GCM/HTTP或CCS向您的应用程序发送消息。
//对于这个演示:我们不需要发送它,因为设备
//将向回显消息的服务器发送上游消息
//使用邮件中的“发件人”地址。
//保存注册表-无需再次注册。
setRegistrationId(上下文,regid);
}捕获(IOEX异常){
msg=“错误:”+ex.getMessage();
}
返回味精;
}
@凌驾
受保护的void onPostExecute(字符串msg){
mDisplay.append((字符串)msg.toString()+“\n”);
}
}.执行(空,空,空);
}

这是舱单



有什么想法吗?

我不确定它是否能解决您的问题,但以下行不再是必需的,应该从您的清单中删除:

<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

此外,您不再需要以下行(尽管它与您得到的错误无关):


8/23/13编辑:

当我使用API 8构建应用程序并在清单中声明时:

我没有得到这个错误

在我使用API 10构建应用程序并将清单更改为:


我犯了这个错误。我不知道这是否有帮助,因为您的targetSdkVersion是17,所以您可能正在使用高级功能。

顺便说一句,我需要您通知我,我没有使用任何IntentService类,我有一个自定义广播接收器类。我也有同样的问题,在我的情况下,问题是由wi-fi连接断开引起的。所以,请检查您是否已连接到internet,然后重试。如果我使用gcmregistar.register(这是发件人ID),它将正常工作。我不认为这是问题所在,但还是要谢谢你。请在你的问题中包含你的清单。请参阅编辑清单OK。我试试看,然后告诉你结果。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pushnotificationexample"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!--
 Creates a custom permission so only this app can receive its messages.

 NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
       where PACKAGE is the application's package name.
-->
<permission
    android:name="com.example.pushnotificationexample.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission
    android:name="com.example.pushnotificationexample.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission
    android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >        

    <activity
        android:name="com.example.pushnotificationexample.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <receiver
        android:name="com.example.pushnotificationexample.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.example.pushnotificationexample" />
        </intent-filter>
    </receiver>               

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

    </application>

</manifest>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<service android:name=".GCMIntentService" />