INVALID_SENDER error at GCM registration

前端 未结 4 1011
攒了一身酷
攒了一身酷 2021-01-19 10:11

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 sende

4条回答
  •  天涯浪人
    2021-01-19 10:19

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

提交回复
热议问题