1

it's been two days that I'm on this Issue

I'm trying to integrate GCM on an android app on eclipse environment. Everything works like a charm but once I have to receive the push notification message I have

03-07 12:19:43.725: W/dalvikvm(4364): Unable to resolve superclass of Lcom/google/android/gms/gcm/GcmReceiver; (331) 03-07 12:19:43.725: W/dalvikvm(4364): Link of class 'Lcom/google/android/gms/gcm/GcmReceiver;' failed 03-07 12:19:43.730: D/AndroidRuntime(4364): Shutting down VM 03-07 12:19:43.730: W/dalvikvm(4364): threadid=1: thread exiting with uncaught exception (group=0x411c42a0) 03-07 12:19:43.825: E/AndroidRuntime(4364): FATAL EXCEPTION: main 03-07 12:19:43.825: E/AndroidRuntime(4364): java.lang.RuntimeException: Unable to instantiate receiver com.google.android.gms.gcm.GcmReceiver: java.lang.ClassNotFoundException: com.google.android.gms.gcm.GcmReceiver

My Google play Lib is integrated and works great, my receiver is already declared in the manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.media.dailydeals"
    android:versionCode="1"
    android:versionName="0.1" >

    <uses-sdk
        android:minSdkVersion="7"
        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.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <application
        android:name="com.media.dailydeals.App"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <activity
            android:name="com.media.dailydeals.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.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.media.dailydeals"/>
            </intent-filter>
        </receiver>
        <service
            android:name="com.media.dailydeals.GcmBroadcastReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <activity
            android:name="com.facebook.LoginActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
   <meta-data
            android:name="com.google.android.gms.analytics.globalConfigResource"
            android:resource="@xml/global_tracker" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />

        <receiver
            android:name="com.google.android.gms.analytics.AnalyticsReceiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
            </intent-filter>
        </receiver>
        <service
            android:name="com.google.android.gms.analytics.AnalyticsService"
            android:enabled="true"
            android:exported="false" />


    </application>

</manifest>

My GcmReceiver class is in the google play library, so I don't get how it can't link it.

I tried to do it with the Jar lib, I rebuild, cleaned the project, I even deleted the reinstalled all the workspace. It's kind of my last shot here

Any help would be much appreciated.

Thanks in advance.

Tunos
  • 11
  • 4
  • Make sure the google play library is in **libs** folder and right click on the library and choose **add as library**. This will link the library with the project. – Faraz Mar 07 '16 at 12:28
  • hi ᖷAЯAƸ I don't have "add as library" when I right click (I'm on eclipse) – Tunos Mar 07 '16 at 12:31
  • I thought you are using Android Studio... I found an answer for linking a library in Eclipse (http://stackoverflow.com/a/6859020/5722608). – Faraz Mar 07 '16 at 12:37
  • I already did this, all the lib is working great as I'm using analytics packed in Google Play Services, It's only the GcmReceiver class that is not linked, and I don't Know why – Tunos Mar 07 '16 at 13:03
  • Any other ideas to help me ? I just need to get this class linked – Tunos Mar 07 '16 at 15:19
  • Can you post `manifest.xml` ? – Faraz Mar 07 '16 at 15:42
  • Try [this](http://stackoverflow.com/a/19429503/5722608) and [this](http://stackoverflow.com/a/20326883/5722608). If this also didn't work, I recommend you to switch to Android Studio. – Faraz Mar 08 '16 at 06:27
  • Nobody with an example of an integration of the new GCM with Eclipse ? With GcmReceiver instead of the old GCMBroadcastReceiver. TIA – Tunos Mar 08 '16 at 13:25

3 Answers3

2

I'm just going to go on a whim here and guess that the issue is either that you don't have support-v4 library included in your project (since com.google.android.gms.gcm.GcmReceiver extends android.support.v4.content.WakefulBroadcastReceiver) or your Eclipse project is misconfigured as described in this answer.

Disclaimer, I never used Eclipse, a quick googling on "Unable to resolve superclass" made me think this would be the answer.

Community
  • 1
  • 1
Zharf
  • 2,638
  • 25
  • 26
  • And the Trophy goes to @Zharf !!!!! The link to Android support V4 was great. But the support.v4 was out of date, so I change it and BANG, I can Receive push in my app. <3 – Tunos Mar 08 '16 at 18:33
0

What is the intention of the notification in your application ? if only to notify and open certain activity , you should create your own BroadcastReceiver that will call a service and treat notification.

instead of using : android : name = "com.google.android.gms.gcm.GcmReceiver ", use : android : name = ".util_gcm.GcmBroadcastReceiver". that would be the way of your BroadCast.

Exemple BroadCast:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());

    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}

}

This BroadCast call GcmIntentService, that treat notification. :

public class GcmIntentService extends IntentService {
public static final String TAG = "Script";
private static final String PREF_NAME = "notification";


public GcmIntentService(){
    super("GcmIntentService");
}

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(GcmIntentService.this);

    String title, cod, link,tipo, conteudo, messageType = gcm.getMessageType(intent);


    if(extras != null){
        if(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)){
            Log.i(TAG, "Error: "+extras.toString());
        }
        else if(GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)){
            Log.i(TAG, "Deleted: "+extras.toString());
        }
        else if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)){

            title = extras.getString("titulo");

            link = extras.getString("link");
            tipo = extras.getString("tipo");


            //NotificationCustomUtil.sendNotification(GcmIntentService.this, title, cod,tipo);
                NotificationCustomUtil.sendNotification(GcmIntentService.this, title,tipo,link);
            }


        }
    }

    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

}

Forget not to declare the service in manifest:

<service android:name=".util_gcm.GcmIntentService" >
    </service>

I hope you have helped in something . :)

  • WakefulBroadcastReceiver aint in the lib anymore Android Developer page suggest the following. For existing apps that extend a WakefulBroadcastReceiver, Google recommends migrating to GCMReceiver and GcmListenerService. To migrate: In the app manifest, replace your GcmBroadcastReceiver with "com.google.android.gms.gcm.GcmReceiver", and replace the current service declaration that extends IntentService to the new GcmListenerService Remove the BroadcastReceiver implementation from your client code Refactor the current IntentService service implementation to use GcmListenerService – Tunos Mar 07 '16 at 13:34
0

@Tunos, we can back track your set up of GCM for your android. Check the manifest files if you have included all required GCM permission:

<manifest package="com.example.gcm" ...>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

<application
...
/>
</manifest>

implementation:

<service android:name=".RegistrationIntentService" android:exported="false"/>

receiver and message handler:

<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.codepath.gcmquickstart" />
</intent-filter>
</receiver>

These are only some of the checklist you should review in debugging your code. Here is the complete checklist regarding GCM. Also refer to this document.

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91