Skip to content

feat(android): allow native receivers for notification actions - #17

Open
SaebAmini wants to merge 1 commit into
ionic-team:mainfrom
SaebAmini:feat/android-native-action-receiver
Open

SaebAmini wants to merge 1 commit into
ionic-team:mainfrom
SaebAmini:feat/android-native-action-receiver

Conversation

@SaebAmini

@SaebAmini SaebAmini commented Oct 25, 2026 •

Copy link
Copy Markdown

Summary

Allow an action type's buttons to target an app-owned Android BroadcastReceiver instead of launching the activity. This supports native actions such as snooze or mark-as-done without opening the app or relying on a running WebView.

Opt in through two LocalNotifications configuration properties:

LocalNotifications: {
  nativeActionTypeId: 'reminder-actions',
  nativeActionReceiver: 'com.example.app.ReminderActionReceiver',
}

The receiver must be declared in AndroidManifest.xml, for example with android:exported="false". It receives the same notification/action intent extras used by the activity path:

  • LocalNotificationManager.NOTIFICATION_INTENT_KEY: notification ID
  • LocalNotificationManager.ACTION_INTENT_KEY: action ID
  • LocalNotificationManager.NOTIFICATION_OBJ_INTENT_KEY: original notification JSON
  • For inline input, RemoteInput.getResultsFromIntent(intent) with LocalNotificationManager.REMOTE_INPUT_KEY

The receiver handles the action natively, including any dismissal or rescheduling. These buttons do not launch the activity or emit localNotificationActionPerformed to JavaScript.

Behavior and scope

  • Existing activity-based actions remain the default.
  • Notification content taps and other action types are unchanged.
  • Broadcasts explicitly target the configured receiver inside the app package.
  • Unique intent actions distinguish notification/action pairs even if integer request codes collide.
  • Ordinary action broadcasts are immutable; inline-input actions remain mutable where required for RemoteInput.

I considered extending foreground: false to Android, but that would suggest that JavaScript handlers can run reliably without an activity/WebView. This explicitly native opt-in keeps that distinction clear and preserves existing behavior.

Only Kotlin intent routing and TypeScript configuration declarations are changed.

Related historical report: ionic-team/capacitor-plugins#512. Android's own notification action example uses a broadcast for snooze: https://developer.android.com/develop/ui/compose/notifications/create-notification#Actions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant