Reputation: 15219
I'm trying to register an Android app with google GCM and it seems to be causing an error in eclipse. Any Help?
blows up as soon as I try to check if its registered. Its compiles fine and I have added the import com.google.android.gcm.GCMRegistrar;
I think this is more about me not understanding java and eclipse, than GCM, but who knows
I've added step filters to ignore com.google.android.gcm.*
and I've made sure to include the gdm.jar library in my local libs folder with my project and the build path.
If i step through the code, it stops when I try to step over the first line where GCMRegistrar
is referenced and says and says 'source not found'. If I put no breakpoints, it still stops when it hits GCMRegistrar
and says 'source not found'.
private void checkRegistration(){
try{
if (!GCMRegistrar.isRegistered(getApplicationContext())) {
// Automatically registers application on startup.
GCMRegistrar.register(getApplicationContext(), Utilities.GCM_SENDER_ID);
} else {
final String regId = GCMRegistrar.getRegistrationId(getApplicationContext());
if(regId.equals("")){
GCMRegistrar.register(getApplicationContext(), Utilities.GCM_SENDER_ID);
}else{
// Device is already registered on GCM
if(regId == Utilities.getGcmRegKey(this)){
}else{
pwClient.updateGCMRef("add", regId, Utilities.getApiKey(this), Utilities.getDeviceId(this));
Utilities.setGcmRegKey(this, regId);
}
}
}
}catch(Exception ex){
Log.e("PW", "register error: " + ex.getMessage());
}
}
}
Upvotes: 0
Views: 1648
Reputation: 13436
According to here, GCM requires Android 2.2 or later, first check if your manifest sdk versions are correct
Second, right click on your project and select Properties => Java Build Path => Libraries tab and ensure gcm.jar exist in the list
Upvotes: 0
Reputation: 23873
I had to stop working on my GCM project, but I did at least manage to get the source for the GCM client side stuff, so it might help you debug a bit. Starting with the R17 SDK tools Google have made attaching source and javadocs a right pain, but it can be done.
In the same 'dist' directory where you found the gcm.jar is another jar gcm-src.jar - that's the source. So in your libs directory make a new file called gcm.jar.properties.
It should contain one line like
src=C:\\dev\\tools\\android-sdk-windows4.1\\extras\\google\\gcm\\gcm-client\\dist\\gcm-src.jar
(Edit this to refer to your SDK installation, changing the \\s to /s if you are on Linux)
Now close your project and reopen it, otherwise it won't work, heaven knows why!
You should now have 'hover over' javadoc type popups and be able to step into the GCMRegistrar static methods. As to why your code blows up, maybe this will get you closer.
Incidentally the sample code I based my project on had these two lines at the start of the registration
// Check that the device supports GCM (should be in a try / catch)
GCMRegistrar.checkDevice(this);
// Check the manifest to be sure this app has all the required permissions.
GCMRegistrar.checkManifest(this);
They might shed some light on things
Upvotes: 3