这里的代码可以解决你的问题.....
在启动画面中运行此代码.....
class GCMRegisterAsync extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
GCMRegistrar.checkDevice(yourclass.this);
GCMRegistrar.checkManifest(yourclass.this);
final String regId = GCMRegistrar
.getRegistrationId(yourclass.this);
if (regId.equals("")) {
GCMRegistrar.register(yourclass.this, "xxxxxxxxxxxx");
} else {
Log.d("test", "Already registered");
}
GCMRegistrar.checkDevice(yourclass.this);
Log.d("info",
"unregistereddd....."
+ GCMRegistrar.getRegistrationId(yourclass.this));
GCMRegistrar.checkManifest(yourclass.this);
if (GCMRegistrar.isRegistered(yourclass.this)) {
Log.e("info gcm id is ",
GCMRegistrar.getRegistrationId(yourclass.this));
}
secondclass.regId = GCMRegistrar
.getRegistrationId(yourclass.this);
if (RegisterHalf.regId.equals("")) {
// replace this with the project ID
GCMRegistrar.register(yourclass.this, "xxxxxxxxxxxx");
Log.e("reg id is ",
GCMRegistrar.getRegistrationId(yourclass.this)
);
} else {
Log.e("info", "already registered as" + RegisterHalf.regId);
}
return null;
}
}
在此之后,将要保存 id 的代码粘贴到数据库中..
SharedPreferences pref = getSharedPreferences(
com.omega.expert.classes.SharedPrefConstants.pref_name, MODE_PRIVATE);
GCMRegistrar.checkDevice(yourclass.this);
GCMRegistrar.checkManifest(yourclass.this);
regId = GCMRegistrar.getRegistrationId(yourclass.this);
Log.e("test", "Reg id:" + regId);
pref.edit().putString(com.omega.expert.classes.SharedPrefConstants.key_gcmid, regId)
.commit();
regId 是您的设备 ID...
保存到数据库....
我已成功实施。这
您的多设备 id 问题将得到解决...