ionic-team / ionic-team/capacitor-local-notifications

LocalNotifications: PRIORITY_DEFAULT prevents heads-up on Xiaomi/MIUI

Open
#9 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
0
Forks
0
Avg merge
11h 50m
Merged PRs (30d)
2

Description

## 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:

```java
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:
```java
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:
```java
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
```
to:
```java
.setPriority(NotificationCompat.PRIORITY_HIGH)
```

Or better, make it configurable via the NotificationSchema:
```typescript
await LocalNotifications.schedule({
notifications: [{
title: "Test",
body: "Test notification",
priority: "high"
}]
});
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.