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 に答える