Take the 2-minute tour ×

I have a problem when my GCMIntentService is called, an exception is thrown:

java.lang.ClassCastException: com.test.test.GCMIntentService cannot be cast to android.content.BroadcastReceiver

However my class does extend the GCMBaseIntentService, in fact my construct "ends" well (the super(SENDER_ID); is passed without issues) and the problem comes when exiting the constructor, I suspect when an internal class tries to cast the newly created instance of my extending class.

Code for reference if needed:

package com.adk.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Notification;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import utilities.Logd;

import com.google.android.gcm.GCMBaseIntentService;
import com.google.android.gcm.GCMConstants;
import com.google.android.gcm.GCMRegistrar;

public class GCMIntentService extends GCMBaseIntentService {

    private final String LOG_TAG = "Test";
    private final static String senderID = "66610078X85X";

    public GCMIntentService(){
        Logd.i(LOG_TAG, "GCM passed");

    protected void onError(Context arg0, String errorID) {
        Logd.e(LOG_TAG, errorID, null);

    protected void onMessage(Context arg0, Intent intent) {
        enviarNotificacion(arg0, intent);


    protected void onRegistered(Context arg0, String deviceID) {
        Registrar(arg0, deviceID);      
        Logd.i(LOG_TAG, "Registered");

    protected void onUnregistered(Context arg0, String arg1) {
        Logd.i(LOG_TAG, "Unregistered");


share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Consider passing a GCMBroadcastReceiver to whatever you're passing the GCMIntentService to. You shouldn't need to inherit and override the name, since it looks like your intent service already has the right name.

share|improve this answer
I'm not passing to anything :S I just call GCMRegistrar.register(act, SENDER_ID); and the constructor is called, I think GCMRegistrar tries to cast it. –  Andres Duran Kenny-Espinosa Jul 23 '12 at 2:29
Intriguing. Have you called GCMBroadcastReceiver.checkManifest()? –  Iain Jul 23 '12 at 2:34
yes, well I called GCMRegistrar.checkManifest(), should I post the manifest? –  Andres Duran Kenny-Espinosa Jul 23 '12 at 2:36
As long as it's not throwing java.lang.IllegalStateException, it doesn't seem necessary. I'm a bit stumped, though. The only thing I can think of is if in your manifest you have <receiver android:name="com.google.android.gcm.GCMIntentService" android:permission="com.google.android.c2dm.permission.SEND" > rather than <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >, but that seems improbable. –  Iain Jul 23 '12 at 3:54
developer.android.com/guide/google/gcm/gs.html step 4 says otherwise. The way it all hangs together is that you point that bit of your manifest at their BroadcastReceiver, and their BroadcastReceiver will then load your IntentService. –  Iain Jul 23 '12 at 16:05
show 3 more comments

The exception indicates the framework is trying to access your GCMIntentService at:


But your source code has the package name set to:

package com.adk.test;

I think changing your package name to com.test.test should work.

Or, if you prefer to stick with com.adk.test.GCMIntentService, then modify your AndroidManifest.xml's GCM receiver to:

<receiver android:name="com.adk.test.GCMIntentService" .... />
share|improve this answer
add comment

Your Answer


