androidnotificationsandroid-notificationsheads-up-notificationsmiui

MIUI heads up notification not working


I'm struggling to get my notifications to display heads up or peek as it is also called.

It is working fine with stock Android and Lineage OS API 21-26

What needs to be done to get it to work in MIUI 8?

The app has ALL notification permissions allowed.

This is an example of my notification code:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context, "service_notifications")
        .setContentTitle(name)
        .setContentText("\uD83D\uDD14" + res.getText(R.string.imminent_arrival_text) + String.valueOf(Long.parseLong(eta) / 60) + res.getText(R.string.minutes_at_text) + simpleETA)
        .setSmallIcon(R.drawable.ic_stat_name)
        .setContentIntent(null)
        .addAction(R.drawable.ic_dialog_close_light, res.getText(R.string.stop_following_label), closePendingIntent)                                
        .setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.quite_impressed))
        .setVibrate(new long[]{1000, 1000})                                    
        .setPriority(NotificationCompat.PRIORITY_MAX)                                    
        .setCategory(NotificationCompat.CATEGORY_MESSAGE);

    notificationManager.notify(
        Constants.NOTIFICATION_ID.FOREGROUND_SERVICE,
        notification.build());
}

Solution

  • You can do this in two ways.

    Go to:

    1. Settings

    2. Installed apps (migrate to your app)

    3. Select your app and go to notifications ( toggle on Priority and also toggle on Floating notification )

    Or, create a remote view(your own layout in res/layout ) and set customHeadsUpNotification

     RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.notif_custom_view);
    
     notification_builder.createHeadsUpContentView(remoteViews);
    

    Don't forget to change the notification_id after doing these changes.