SENDER_ID = Project Number, I was using Project Id.. Project Number is available on console beside project id.
INVALID_SENDER error at GCM registration
-
12-07-2023 - |
题
I am developing application where I want to implement push notification for that I am using GCM, I have registered my project on google console and using project ID as senderID for GCM registraton.
GCMRegistrar.checkDevice(this); //no error
GCMRegistrar.checkManifest(this); //no error
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "********"); //after this..
//onError method of GCMIntentService class
//is triggered, there I am printing error
//in log its saying INVALD_SENDER
}
I have given all required permissions in AndroidManifest.xml
I Have already referred following links
1) Android GCM SENDER_ID, how to get it? 2) Getting GCM Error: INVALID_SENDER occasionally in an app that has two GCM BroadcastReceivers 3) GCM Invalid sender error 4) http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
解决方案
其他提示
Here is a working example for push notifications, hope this helps:
private String SENDER_ID = "xxxxxxx";
private GoogleCloudMessaging gcm;
//somewhere else
gcm = GoogleCloudMessaging.getInstance(context);
String msg = gcm.register(SENDER_ID);
I recently got some service not available errors here so I also implemented a Broadcastreciever to recieve the regestration token.
@Override
public void onReceive(Context context, Intent intent) {
Bundle data = intent.getExtras();
if (data!=null){
String regId = data.getString("registration_id");
}
}