Skip to content

Android 13+/HyperOS (Xiaomi): LocalNotifications.requestPermissions() crashes with NPE in Capacitor getPermissionStates (FATAL EXCEPTION: CapacitorPlugins) #2487

@pruebarub7

Description

@pruebarub7

Bug Report

Plugin(s)

[@capacitor/local-notifications] 8.0.0 (Android)
(Context) Capacitor core/runtime: [@capacitor/core] 8.0.0, [@capacitor/android] 8.0.0, @capacitor/cli 8.0.0

Capacitor Version

   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 8.1.0
  @capacitor/core: 8.1.0
  @capacitor/android: 8.1.0
  @capacitor/ios: 8.1.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 8.0.0
  @capacitor/core: 8.0.0
  @capacitor/android: 8.0.0

[success] Android looking great! 👌

Platform(s)

Android (reproductable in Android 14 and Android 15, with Xiaomi/HyperOS)
Not reproductable in older Android Xiaomi tablet (without [POST_NOTIFICATIONS] runtime)

Current Behavior

  • En algunos dispositivos Xiaomi con HyperOS, al llamar LocalNotifications.requestPermissions() (Android 13+), la app crashea inmediatamente.

  • Logcat (release/R8) shows:
    FATAL EXCEPTION: CapacitorPlugins
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    Caused by: java.lang.NullPointerException
    [at com.getcapacitor..getPermissionStates(...)]
    [at com.getcapacitor.
    .getPermissionState(...)]
    [at com.capacitorjs.plugins.localnotifications.LocalNotificationsPlugin.requestPermissions(...)]

Expected Behavior

Standard permissions dialog for Android is shown for [POST_NOTIFICATIONS] and app doesn't crash.
[LocalNotifications.requestPermissions()] should resolve with final state.

Code Reproduction

Can't publish a public rep for “minimal reproduction”, but it's extremely small:

  • Create an app with Capacitor Android with [@capacitor/local-notifications]
  • Ensure [android.permission.POST_NOTIFICATIONS]
  • With Android 13+, call [LocalNotifications.requestPermissions()] (from a button or toggle).
  • Compilar [release] (R8 enabled) and install in affected Xiaomi/HyperOS.
  • Result: Resultado: crash with NPE at [getPermissionStates]

Snippet (TS) of failure point:

import { LocalNotifications } from '@capacitor/local-notifications';

await LocalNotifications.requestPermissions(); // crash in some Xiaomi HyperOS

Other Technical Details

Workaround that solves the crash:

Ask for [POST_NOTIFICATIONS] using Activity Result API (RequestPermission) in native Android code (avoiding the “permission aliases” flux of Capacitor).
With this, permission is asked/accepted with no error and no crash.

Si el equipo lo prefiere, puedo preparar un repo reproducible mínimo siguiendo las instrucciones del contributing guide (indicadme y lo hago).

Other Technical Details

  • Confirmed affected devices:
    Xiaomi Mi 11 — HyperOS 1.0.12.0.UKBEUXM — Android 14
    Xiaomi Poco F5 — HyperOS 2.0.218.0.VMRMIXM — Android 15

  • targetSdkVersion: 36

  • Build: [release] with minify/shrink (R8)

  • A/B test confirmado:
    Without workaround (using [LocalNotifications.requestPermissions()] in Android): crashes.
    With workaround (permission asked using Activity Result API): doesn't crash, standard PermissionController is shown.

Additional Context

Stacktrace (excerpt) of crash (release/R8):

  • Caused by: java.lang.NullPointerException
    [at com.getcapacitor.D.getPermissionStates(SourceFile:19)]
    [at com.getcapacitor.D.getPermissionState(SourceFile:1)]
    [at com.capacitorjs.plugins.localnotifications.LocalNotificationsPlugin.requestPermissions(SourceFile:9)]

It seems an edge-case/bug at the Android core of Capacitor when solving state for permissions/alias in these HyperOS devices, triggered from LocalNotifications when asking for [POST_NOTIFICATIONS] (Android 13+).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions