Android push notification prompt

Get more opt-ins and give a better experience to your users by customising the opt-in journey.

Up until Android version 12, push notifications on Android were enabled by default and didn't require explicit opt-in from the user. Recently, Android changed its policy and now Android 13 will give users the ability to choose directly in the app if they want to enable push notifications or not.

📘

Prerequisites

In order to set up push notifications, you must first follow the main Android push notifications guide.

In v9.1.0+ of the Xtremepush SDK, the opt-in prompt is off by default. This is to allow you to choose your own strategy for requesting notification access.

If you would like to show the opt-in prompt on app launch, you can enable this by adding the following to PushConnector.Builder:

.requestNotificationPermission(true)

Delay the opt-in or include a value exchange

It is recommended to delay this opt-in prompt until the user has logged in or until they have reached an appropriate section in the app where permission is clearly required, for example, turning on an alerting function.

It is also good practice to display a value exchange screen prior to showing this prompt. This screen would explain why you want to send them push notifications.

👍

Value exchange

Read more about what a value exchange is and why it can help you get more opt-ins on our website.

This screen can contain app-level Allow and Don't Allow buttons, that can set a local flag in the app if the user chooses to refuse. If the user denies granting permission at this stage, you do not show the Android dialog, which means you are able to ask for permission again in the future, instead of having lost your chance by the user denying the OS-level permission.

You can call this prompt again later by calling the following function:

mPushConnector.requestNotificationPermissions(this);
// check if can show permission prompt
if(mPushConnector.canRequestNotificationPermission(this)) {
  //simple value exchange
  AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setTitle("We use Notifications");
  builder.setMessage("Stay up to date with the latest news and offers");
  // add the buttons
  // if user accepts, show notification permission request
  builder.setPositiveButton("Proceed", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
      mPushConnector.requestNotificationPermissions(activity);
    }
  });
  builder.setNegativeButton("Not now", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
      dialog.cancel();
    }
  });
  // create and show the alert dialog
  AlertDialog dialog = builder.create();
  dialog.show();
}
750

Example of a value exchange that would be presented to users before the OS level opt-in prompt.