Java Gcm android应用程序触发同一设备的多个注册
我的GCM应用程序为同一设备生成多个注册。我已经找过了,但是找不到任何解决办法 以下是我的主要活动:Java Gcm android应用程序触发同一设备的多个注册,java,google-cloud-messaging,Java,Google Cloud Messaging,我的GCM应用程序为同一设备生成多个注册。我已经找过了,但是找不到任何解决办法 以下是我的主要活动: public void onCreate(Bundle savedInstanceState) { GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regI
public void onCreate(Bundle savedInstanceState) {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "952039800261");
} else {
Log.v(TAG, "Already registered");
}}
这是我的注册方法::
protected void onRegistered(Context arg0, final String regId) {
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
// sets the app name in the intent
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", senderId);
startService(registrationIntent);
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.ludlowcastle.co.in/moksha/register.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("regId", regId));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
我的服务器上有大约5K个相同设备的注册ID。您正在无限循环中注册 我不使用gcmregistar类,但我很确定gcmregistar.register这个952039800261;是否与这些行相同:
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
// sets the app name in the intent
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", senderId);
startService(registrationIntent);
在我的应用程序中,这4行代码位于我的主要活动的onCreate方法中,而不是gcmregistar调用中
当调用onRegistered时,这意味着注册已成功,并且您有一个注册id。由于您在此方法中要求再次注册,因此会向Google发送一个新的注册请求,然后在下次注册成功时再次调用此方法。我不确定您是否在每次通话中获得不同的注册ID,或者您是否获得相同的注册ID,但只需从onRegistered中删除上述4行即可解决您的问题