Push Notifications

Prev Next

Overview

Push Notifications in Android deliver timely and engaging content directly to users, even when the app is not in use. These notifications can include messages, promotions, or alerts to drive user interaction and engagement.

Use Case

  1. Purpose:

    • Deliver real-time updates, reminders, or promotional messages to users.

    • Enhance app engagement by directing users to relevant app features or content.

  2. Benefits:

    • Reach users when they are not actively using the app.

    • Drive re-engagement with targeted and personalized content.

Implementation Details

  1. Enable/Disable Push Notifications:

    • Dynamically enable or disable push notifications for the device:

      // Enable push notifications
      Appoxee.instance().setPushEnabled(true);
      
      // Disable push notifications
      Appoxee.instance().setPushEnabled(false);
  2. Check Push Notification State:

    • Verify whether push notifications are currently enabled or disabled:

      boolean isPushEnabled = Appoxee.instance().isPushEnabled();
  3. Handle Runtime Permissions:

    • For Android 13 (API level 33) and newer, request the POST_NOTIFICATIONS Runtime permission:

      Appoxee.instance().requestNotificationsPermission(MainActivity.this, results -> {
          if (results.containsKey(Manifest.permission.POST_NOTIFICATIONS) &&
              results.get(Manifest.permission.POST_NOTIFICATIONS) == PermissionsManager.PERMISSION_GRANTED) {
              Log.d("PushNotifications", "Permission Granted");
          }
      });
  4. Handle Notifications:

    • Define a receiver in the AndroidManifest.xml to handle notification events:

      <receiver
          android:name=".MyPushBroadcastReceiver"
          android:enabled="true"
          android:exported="false">
          <intent-filter>
              <action android:name="com.appoxee.PUSH_OPENED"/>
              <action android:name="com.appoxee.PUSH_RECEIVED"/>
              <action android:name="com.appoxee.PUSH_DISMISSED"/>
              <category android:name="${applicationId}"/>
          </intent-filter>
      </receiver>
  5. Notification Handling in Code:

    • Implement the receiver to manage notification events:

      public class MyPushBroadcastReceiver extends PushDataReceiver {
          @Override
          public void onPushReceived(PushData pushData) {
              Log.d("PushNotification", "Notification received: " + pushData);
          }
      
          @Override
          public void onPushOpened(PushData pushData) {
              Log.d("PushNotification", "Notification opened: " + pushData);
          }
      }

Localized Buttons Behavior

The Engage SDK updates its localization configuration once per day. If the app is installed and opened before localized buttons are configured in the Mapp Engage interface, it will fetch the current (non-localized) settings and not update them again for 24 hours.

As a result, notifications—both simple and rich—may display buttons in English instead of the intended localized language.

Tip: To ensure accurate testing, configure localized buttons in the Mapp Engage interface before installing or launching the app. Alternatively, reinstall the app or clear its data to trigger a fresh configuration fetch.

Keep in mind:

  • Ensure proper runtime permissions for Android 13+ to display notifications.

  • Test notification behavior across various app states (foreground, background, and killed).

  • Log notification events for debugging and monitoring.