Skip to content

LocalNotifications: PRIORITY_DEFAULT prevents heads-up on Xiaomi/MIUI #9

Description

@flupke91

Bug Report

Plugin

@capacitor/local-notifications

Capacitor Version

@capacitor/core: 7.x
@capacitor/local-notifications: 7.x

Platform

Android (specifically Xiaomi/MIUI/HyperOS devices)

Current Behavior

The LocalNotificationsPlugin.java hardcodes NotificationCompat.PRIORITY_DEFAULT when building notifications:

NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext(), notification.getChannelId())
    .setSmallIcon(smallIcon)
    .setContentTitle(notification.getTitle())
    .setContentText(notification.getBody())
    .setPriority(NotificationCompat.PRIORITY_DEFAULT)  // hardcoded

On Xiaomi/MIUI/HyperOS devices (Android 11+), PRIORITY_DEFAULT notifications:

  • Do NOT show as heads-up (popup) notifications
  • Silently appear in the status bar only
  • User has no way to see the notification without pulling down the shade

Expected Behavior

Notifications should appear as heads-up popups when:

  1. The channel importance is set to IMPORTANCE_HIGH
  2. The notification priority is PRIORITY_HIGH or PRIORITY_MAX

The plugin should either:

  1. Respect the channel importance level and set priority accordingly
  2. Expose a priority option in the NotificationSchema interface
  3. Default to PRIORITY_HIGH when channel importance is HIGH

Steps to Reproduce

  1. Create a notification channel with importance: 4 (HIGH)
  2. Schedule a notification using LocalNotifications.schedule()
  3. On a Xiaomi device, the notification appears in status bar but NOT as a popup

Workaround

Create a custom native plugin that uses PRIORITY_HIGH:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setCategory(NotificationCompat.CATEGORY_ALARM)
    .setDefaults(NotificationCompat.DEFAULT_ALL);

Additional Context

  • This affects all Xiaomi/MIUI/HyperOS devices (Android 11+)
  • dumpsys notification shows the notification with importance=DEFAULT even when channel is IMPORTANCE_HIGH
  • Setting PRIORITY_HIGH resolves the issue immediately

Suggested Fix

In LocalNotificationsPlugin.java, change:

.setPriority(NotificationCompat.PRIORITY_DEFAULT)

to:

.setPriority(NotificationCompat.PRIORITY_HIGH)

Or better, make it configurable via the NotificationSchema:

await LocalNotifications.schedule({
  notifications: [{
    title: "Test",
    body: "Test notification",
    priority: "high"
  }]
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions