Silent Push

Prev Next

Overview

Silent Push Notifications in Android allow developers to send notifications that do not alert the user. These notifications are typically used for background updates, such as syncing data, fetching new content, or triggering specific app actions without user intervention.

Use Case

  1. Purpose:

    • Deliver background updates to the app without interrupting the user.

    • Trigger app-specific actions like updating user preferences or syncing content.

  2. Benefits:

    • Maintain user engagement by keeping the app updated.

    • Avoid disturbing users with unnecessary alerts.

Implementation Details

  1. Silent Push Payload:

    • Silent pushes require a specific payload with no notification content:

      {
          "to": "<device_token>",
          "data": {
              "action": "update_content",
              "content_id": "12345"
          },
          "content_available": true,
          "priority": "high"
      }
    • The content_available field is critical for silent notifications.

  2. Handle Silent Pushes:

    • Implement a BroadcastReceiver to process silent push payloads:

      public class SilentPushReceiver extends PushDataReceiver {
          @Override
          public void onSilentPush(PushData pushData) {
              Log.d("SilentPush", "Silent push received: " + pushData);
      
              String action = pushData.getCustomData("action");
              if ("update_content".equals(action)) {
                  // Perform background update or sync
                  syncContent(pushData.getCustomData("content_id"));
              }
          }
      
          private void syncContent(String contentId) {
              // Add logic to fetch and sync content
              Log.d("SilentPush", "Syncing content with ID: " + contentId);
          }
      }
  3. Configuration:

    • Update AndroidManifest.xml to register the receiver:

      <receiver android:name=".SilentPushReceiver"
                android:exported="false">
          <intent-filter>
              <action android:name="com.appoxee.SILENT_PUSH" />
              <category android:name="${applicationId}" />
          </intent-filter>
      </receiver>

Keep in mind:

  • Silent pushes require priority: high to ensure they are delivered promptly.

  • Test background processing across devices and Android versions to ensure reliability.

  • Ensure the app handles silent pushes efficiently to avoid battery drain.