0

我正在使用 GCM。它的工作完美,但取消注册后我仍然收到通知。

这是我的注册:

     // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(context);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(context);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(
            DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(context);

    // Check if regid already presents
    if (regId.equals("")) {
        // Registration is not present, register now with GCM           
        GCMRegistrar.register(context, SENDER_ID);
    } else {
        // Device is already registered on GCM
        if (GCMRegistrar.isRegisteredOnServer(context)) {
            // Skips registration.              
            Toast.makeText(context, "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 instead of a raw thread.

            mRegisterTask = new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    // Register on our server
                    // On server creates a new user
                    ServerUtilities.register(context, user, pass, regId);
                    return null;
                }

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

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

从不同的活动中,我试图从 GCM 注销:

GCMRegistrar.unregister(getApplicationContext());
    GCMRegistrar.onDestroy(getApplicationContext());

之后我仍然收到通知:(

4

1 回答 1

0

首先,GCMRegistrar已弃用。

其次,unregister()表示此设备不应再接收消息。频繁注册和注销不是预期的应用程序行为。如果您想停止接收消息,请告诉您的应用服务器停止发送消息。

于 2013-09-24T11:29:02.940 回答