Pergunta

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/

Foi útil?

Solução

SENDER_ID = Project Number, I was using Project Id.. Project Number is available on console beside project id.

Outras dicas

Google has changed its layout. you can find project_number from here

select project -> My Project

click three dots -> Project Information -> Project Number

enter image description here

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");
    }
}

I got same error and found out that google login was not enabled in firebase console. After enabling it error was gone.

Check this image for reference:

image

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top