I am trying to implement push notifications via StackMob on an existing Android app. I have gone through their tutorial and dev center to try to find a solution to my problem, but I cannot. In my app's BaseActivity I have my sender ID (actual id replaced with # for obvious reasons):
public static String SENDER_ID = "############";
from the Google API Console. I also have the init function (again, PUBLIC and PRIVATE keys replaced in this code):
StackMobAndroid.init(this.getApplicationContext(), StackMob.OAuthVersion.One, 0, "<PUBLIC KEY FROM STACKMOB DASHBOARD>", "<PRIVATE KEY FROM STACKMOB DASHBOARD>");
From what I understand, I also need to register any devices to recieve the notifications, which is just below the init:
try {
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
registerForPush();
} else {
Log.e("BaseActivity", "User already registered for push notifications");
}
} catch (UnsupportedOperationException e) {
Log.e("BaseActivity", "This device doesn't support gcm. Push will not work");
}
private void registerForPush() {
GCMRegistrar.register(this, SENDER_ID);
}
When I run my app, I get Registering app com.example.android of senders ############
in LogCat, so AFAIK my device is registered to get push notifications. But when I try sending a push notification from the StackMob dashboard and check the Log from that push, I see
Failed to send message {"alert":"deadbeef"} because there is no C2DM ClientLogin token for version=0
Can somebody explain what that log message is actually telling me?
There are two versions of Android push: the old one C2DM and the new one GCM. You can register tokens for either of these and StackMob will send a message using the appropriate credentials. C2DM has been deprecated, so all the SDKs register tokens as GCM by default and that's what the push instructions have you configure with the sender_id and all that.
Your token has accidentally been registered as C2DM somehow. When we go to push we see you have no credentials there and print that message. The solution is to remove the token via the push console and register it again as GCM. https://dashboard.stackmob.com/data/console
The real question is how you ended up registering a C2DM token in the first place. If any StackMob tool or demo doesn't have GCM as a default and C2DM clearly marked as legacy, let me know.