我目前正在我的应用程序中实现 GCM。我使用了教程here作为起点。
问题是我的 regId
始终为 null
:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals(""))
{
GCMRegistrar.register(this, "627xxxx78");
}
else
{
if (GCMRegistrar.isRegisteredOnServer(this))
{
Log.i(TAG, "Already registered regId : " + regId );
}
else
{
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
boolean registered =
ServerUtilities.register(context, regId);
if (!registered)
{
GCMRegistrar.unregister(context);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}
};
mRegisterTask.execute(null, null, null);
}
}
在上面的代码中,ServerUtilities.register
从未被调用,因为 GCMRegistrar.getRegistrationId(this)
;始终返回空字符串。
有什么想法吗?
最佳答案
确保您的模拟器或设备已使用 Google 帐户登录。我遇到了同样的问题。我只是登录了设备的谷歌帐户,哈哈,我得到了 regId。
关于java - regId 始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12286356/