Android GCM注册失败.为什么?

ser*_*tem 2 java android push-notification google-cloud-messaging

我试图使用GCM在我的应用程序中进行推送通知.我打电话给我GCMRegistrar.register(this, SENDER_ID),但是我收到了一个错误.

我的清单文件:

   <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.salamworld"/>
        </intent-filter>
    </receiver>
    <service android:name=".GCMIntentService"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<permission android:name="my.package.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="my.package.permission.C2D_MESSAGE"/>
<uses-sdk android:minSdkVersion="8"/>
Run Code Online (Sandbox Code Playgroud)

这是错误:

DEBUG/GCMBaseIntentService(423):注册错误:ACCOUNT_MISSING

我的GCMIntentService类:

public class GCMIntentService extends GCMBaseIntentService{

    public GCMIntentService() {
        super();
    }

    @Override
    protected void onMessage(Context context, Intent intent) {
    }

    @Override
    protected void onError(Context context, String errorId) {
    }

    @Override
    protected void onRegistered(Context context, String registrationId) {
        Log.d("@R@", registrationId);
    }

    @Override
    protected void onUnregistered(Context context, String registrationId) {
    }
}
Run Code Online (Sandbox Code Playgroud)

Lal*_*ani 7

如果您的设备中没有Google帐户,则会出现此例外情况,

ACCOUNT_MISSING - 手机上没有Google帐户.Android应用程序应该要求用户打开帐户管理员并添加Google帐户.修复设备端.

  • @ servus-libertatem您可以在模拟器中添加Google帐户.确保您已使用Google API(API级别)创建了一个模拟器. (4认同)
  • 您最好尝试使用设备,因为您的模拟器默认情况下未配置为具有Google帐户.[你也可以查看这个答案](http://stackoverflow.com/a/3796495/726863) (2认同)