Peppegiuseppe
Peppegiuseppe

Reputation: 183

Google Cloud Messaging Error: Unable to instantiate receiver

I've followed google guide about new GCM with Google Play Services and after hours of developing i managed to register my device on GCM server, to obtain the REGISTER_ID and to create a php script which correctly send a post request.

The bad news is that i don't manage to receive my push notification, when i run my app logcat shows this error:

12-19 19:48:24.405: E/AndroidRuntime(9570): FATAL EXCEPTION: main
12-19 19:48:24.405: E/AndroidRuntime(9570): java.lang.RuntimeException: Unable to instantiate receiver com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver:
                                            java.lang.ClassNotFoundException: com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver
12-19 19:48:24.405: E/AndroidRuntime(9570):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2112)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at android.app.ActivityThread.access$1500(ActivityThread.java:127)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at android.os.Looper.loop(Looper.java:137)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at android.app.ActivityThread.main(ActivityThread.java:4507)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at java.lang.reflect.Method.invokeNative(Native Method)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at java.lang.reflect.Method.invoke(Method.java:511)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at dalvik.system.NativeStart.main(Native Method)
12-19 19:48:24.405: E/AndroidRuntime(9570): Caused by: java.lang.ClassNotFoundException: com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver
12-19 19:48:24.405: E/AndroidRuntime(9570):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-19 19:48:24.405: E/AndroidRuntime(9570):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2107)
12-19 19:48:24.405: E/AndroidRuntime(9570):     ... 10 more
12-19 19:48:52.620: I/Process(9570): Sending signal. PID: 9570 SIG: 9

This is my Manifest (i've omitted the unnecessary parts of code):

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17"
    />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<permission android:name="com.baruckis.SlidingMenuImplementation.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.baruckis.SlidingMenuImplementation.permission.C2D_MESSAGE" />

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

<application

               [...]

<receiver
        android:name="com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.baruckis.SlidingMenuImplementation" />
        </intent-filter>
</receiver>

<service android:name="com.baruckis.SlidingMenuImplementation.GcmIntentService" />
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
    </application>

And finally this is my GcmBroadcastReceiver code:

package com.baruckis.SlidingMenuImplementation;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(),
            GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
   }
}

Thanks to all! :)

Upvotes: 0

Views: 783

Answers (1)

Eric Schlenz
Eric Schlenz

Reputation: 2581

Try extending the provided: com.google.android.gcm.GCMBroadcastReceiver

public class MyGCMBroadcastReceiver extends com.google.android.gcm.GCMBroadcastReceiver {
    protected String getGCMIntentServiceClassName(Context context) {
        return GCMIntentService.class.getName();
    }
}

Upvotes: 1

Related Questions