I am trying to register a device onto GCM using the following code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GCMRegistrar.checkDevice(this);
// the following function can be removed when deploying the app
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
} else {
Log.v(TAG, "Already registered");
}
I have imported import com.google.android.gcm.GCMRegistrar;
and also added GCM.jar to my buildpath in Eclipse which i got thru the sdk download
Please help !
In the updated ADT(Above ADT 17) you have to put jar files inside libs
folder and not lib
. So make sure that you put gcm.jar
file inside libs
and not lib
folder.
Just go to project properties -> java build path -> "order and export " now giv a tick on the jar file "GCM.jar" that you have added
My gcm.jar
was already in libs, so it wasn't a folder naming issue for me..
I had to go to Right Click
> Build Path
> Configure Build path...
for the project in question and I removed the following:
Android Private Libraries
You might get a lot of "errors" in your project so restart Eclipse and let it clean. Once it cleans you'll have no errors. Run your project and viola.
Thanks to DLew for this answer.
Make a folder libs in your project folder and put the gcm.jar in it. Then add it to your class path using add external jars in configure build path option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With