Christopher Francisco
Christopher Francisco

Reputation: 16278

Google cloud messaging starting issues

I'm new to BroadcastReceiver and to Service and GoogleCloudMessaging. I'm following the tutorial at http://developer.android.com/google/gcm/gs.html

After I imported the library to my workspace and referenced it to my project, I'm getting a Runtime exception "No class def found error". I browsed over the Internet and found that maybe the mistake has to do with my AndroidManifest.xml and it could make sense since I have no idea of some things about the manifest that are described in the tutorial.

For example:

<receiver
    android:name=".MyBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="com.my.package" />
    </intent-filter>
</receiver>
<service android:name=".MyIntentService" />

The first thing is that in the tutorial, they declare a receiver with the name "MyBroadcastReceiver" BUT latter on they define a class named "GcmBroadcastReceiver" which extends BroadcastReceiver. So I don't know if they are 2 different things, or it's a mistake and they should be named the same.

The second thing is the Service. There is no service in the tutorial. So I guess I'm suppose to create a service

The third thing is that, I don't understand how or where is the BroadcastReceiver and/or Service called from the MainActivity, how are they linked together and so on.

EDIT: I'm using the new Google Cloud Messaging API

Upvotes: 0

Views: 281

Answers (1)

Eran
Eran

Reputation: 394026

The service is no longer required. It was used with the older API. It was called by the broadcast receiver for handling arriving messages and registration results, but now all the handling of arriving messages is done in the broadcast receiver.

You need a broadcast receiver class. It doesn't matter how you call it. GcmBroadcastReceiver is the class they created for the demo app. The name MyBroadcastReceiver suggests that you should create your on class. The broadcast receiver is not called from the main activity. It is called when a GCM message is sent to your app.

And as for your No class def found error, assuming you're using Eclipse, you probably missed checking the Java Build Path -> Order and Export -> Android Private Libraries flag in your Android project.

Upvotes: 1

Related Questions