gpt4 book ai didi

android - GCM 服务器端的多个应用程序 ID

转载 作者:行者123 更新时间:2023-11-29 21:48:43 24 4
gpt4 key购买 nike

在服务器端,我发现一台设备有多个注册 ID,这显然给我带来了很多问题。喜欢多次收到的消息。

如果有有效的注册 ID,我怎样才能让旧的注册 ID 变红,或者确保不会发生注册。

当我编写我的应用程序时,我遵循 Android 文档上的示例教程,如下所示:

 checkNotNull(SERVER_URL, "SERVER_URL");
checkNotNull(SENDER_ID, "SENDER_ID");
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);
// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
// NOT required any more GCMRegistrar.checkManifest(this);

/**
* this code to register reciver moved to message actvity
*/
//registerReceiver(mHandleMessageReceiver, new IntentFilter(
// DISPLAY_MESSAGE_ACTION));


/* final String */regId = GCMRegistrar.getRegistrationId(this);

/**
* save regId in pref to be used by Location update service
*/
SavePreferences("regId", regId);

if (regId.equals("")) {
// Automatically registers application on startup.
GCMRegistrar.register(this, SENDER_ID);
} else {
// Device is already registered on GCM, check server.
if (GCMRegistrar.isRegisteredOnServer(this)) {
;;
// Skips registration.
// -- mDisplay.append(getString(R.string.already_registered) +
// "\n");
// System.out.println(getString(R.string.already_registered)
// + "\n");

} 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 instead of a raw thread.
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {

@Override
protected Void doInBackground(Void... params) {
boolean registered = ServerUtilities.register(context,
regId);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
GCMRegistrar.unregister(context);
}
return null;
}

@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}

};
mRegisterTask.execute(null, null, null);
}
}

最佳答案

Please refer link: http://stackoverflow.com/questions/15030233/gcm-multiple-application-id-in-server-side/15030465#comment21123039_15030465

Also check canonical registration ids concept :http://developer.android.com/google/gcm/adv.html

or

when a new id is generated you will try to register it GCM registrar. when this new registration id successfully register your onRegister() method of service will be called .

here you can add code to replace previous one with new one.but for this along with registration id you need to send some unique reference to server,so for next time you can check this unique reference and replace existing registration id with new one

checked following code:

@Override

protected void onRegistered(Context context, String registrationId) {

ServiceUtilities.register(context, registrationId);
//call service and replace id
}

关于android - GCM 服务器端的多个应用程序 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15031167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com