Skip to content

How to completely stop or start receiving push messages

Olga Koroleva edited this page Nov 9, 2022 · 7 revisions

Important

Push registration is enabled by default, that means that you don't need to use method for enabling it. Disabled push registration is the one that will completely stop receiving push notifications. Disabling push registration is needed to be used only if you want to opt out of receiving notifications. If you just don't want notifications to be displayed in the notification center, send silent campaign, or use method .withoutDisplayNotification().

Disabling the push registration

In order to disable the current user from receiving push messages, you have to change his push registration status. Here are the steps:

  1. Start MobileMessaging SDK in a way it's described in the Quick Start Guide if it is not started yet.
  2. Once the SDK has been successfully initialized and started, do the following:
val installation = Installation()
installation.isPushRegistrationEnabled = false
MobileMessaging.getInstance(context).saveInstallation(installation, object : ResultListener<Installation>() {
    override fun onResult(result: Result<Installation, MobileMessagingError>) {
        // process result here
    }
})
expand to see Java code

Installation installation = new Installation();
installation.setPushRegistrationEnabled(false);
MobileMessaging.getInstance(context).saveInstallation(installation, new ResultListener<Installation>() {
    @Override
    public void onResult(Result<Installation, MobileMessagingError> result) {
        // process result here
    }
});

Enabling the push registration

In order to enable current user back to receiving push messages, you need to enable user's push registration:

  1. Start MobileMessaging SDK in a way it's described in the Quick Start Guide if it is not started yet.
  2. Once the SDK has been successfully initialized and started, do the following:
val installation = Installation()
installation.isPushRegistrationEnabled = true
MobileMessaging.getInstance(context).saveInstallation(installation, object : ResultListener<Installation>() {
    override fun onResult(result: Result<Installation, MobileMessagingError>) {
        // process result here
    }
})
expand to see Java code

Installation installation = new Installation();
installation.setPushRegistrationEnabled(true);
MobileMessaging.getInstance(context).saveInstallation(installation, new ResultListener<Installation>() {
    @Override
    public void onResult(Result<Installation, MobileMessagingError> result) {
        // process result here
    }
});

Retrieving the current push registration status

In order to get the current registration status, use the following code:

var isPushRegistrationEnabled = MobileMessaging.getInstance(this).installation.isPushRegistrationEnabled
expand to see Java code

boolean isPushRegistrationEnabled = MobileMessaging.getInstance(this).getInstallation().isPushRegistrationEnabled();
Clone this wiki locally