我是Android新手,并为gcm推送通知做一个演示应用程序.
我已经开发了所有这些代码,并且GCM推送通知正在我的环境中的设备上出现,但是当我在其他网络设备中测试此代码获得注册ID时,但是当向云发送消息时服务器端获得不匹配的发送者ID响应.我的代码如下:
checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID");
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
setContentView(R.layout.activity_push_android);
mDisplay = (TextView) findViewById(R.id.display);
final String regId = GCMRegistrar.getRegistrationId(this);
Log.i(TAG, "registration id ===== " + regId);
if (regId.equals("")) {
GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
} else {
// Device is already registered on GCM
if (GCMRegistrar.isRegisteredOnServer(this)) {
// Skips registration.
Toast.makeText(getApplicationContext(),
"Already registered with GCM", Toast.LENGTH_LONG)
.show();
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask …Run Code Online (Sandbox Code Playgroud)