GCM注册时出现INVALID_SENDER错误

时间:2014-04-30 06:00:49

标签: android google-api

我正在开发应用程序,我希望为我使用GCM实现推送通知,我已经在谷歌控制台上注册了我的项目,并使用项目ID作为GCM注册的senderID。

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 
        } 

我已在AndroidManifest.xml中提供了所有必需的权限

我已经提到了以下链接

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/

4 个答案:

答案 0 :(得分:21)

SENDER_ID =项目编号,我正在使用项目ID ..项目编号在项目ID旁边的控制台上可用。

答案 1 :(得分:14)

谷歌改变了布局。你可以在这里找到 project_number

选择项目 - > 我的项目

点击三个点 - > 项目信息 - > 项目编号

enter image description here

答案 2 :(得分:0)

以下是推送通知的工作示例,希望这会有所帮助:

private String SENDER_ID = "xxxxxxx";
private GoogleCloudMessaging gcm;

//somewhere else
gcm = GoogleCloudMessaging.getInstance(context);
String msg = gcm.register(SENDER_ID);

我最近在这里得到了一些服务不可用的错误,所以我还实现了一个Broadcastreciever来接收重新生成令牌。

@Override
public void onReceive(Context context, Intent intent) {
    Bundle data = intent.getExtras();
    if (data!=null){
        String regId = data.getString("registration_id");
    }
}

答案 3 :(得分:0)

我遇到了相同的错误,发现在Firebase控制台中未启用google登录。启用后,错误消失了。

检查此图像以供参考:

image