Reputation: 11
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.
Upvotes: 1
Views: 1310
Reputation: 2658
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.
Upvotes: 2
Reputation: 6791
@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.
Upvotes: 0
Reputation: 21
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 . :)
Upvotes: 0