Как включить хедз-ап уведомления на Xiaomi (MIUI 10 Global) - PullRequest
2 голосов
/ 16 апреля 2019

Как программно включить хедз-ап уведомления на устройствах Xiaomi? В некоторых приложениях (например, Telegram) эти разрешения включены по умолчанию.

Скриншот настроек: https://imgur.com/a/D48G8Mz

@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel( ) {
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
    channel.enableLights(true);
    channel.setLightColor(Color.RED);
    channel.enableVibration(true);
    channel.setSound(createNotificationSound(),
            new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .build());
    channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.createNotificationChannel(channel);

    return CHANNEL_ID;
}

Уведомление

    String channelId = "";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        channelId = createNotificationChannel();
    }

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId)
            .setLargeIcon(icon)
            .setSmallIcon(R.mipmap.ic_mipmap_launcher)
            .setContentTitle("Title")
            .setTicker(getResources().getString(R.string.app_name))
            .setContentText("Text")
            .setSound(createNotificationSound(), AudioManager.STREAM_NOTIFICATION)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent)
            .setChannelId(channelId)
            .setPriority(Notification.PRIORITY_HIGH);

    NotificationCompat.InboxStyle inboxStyle =
            new NotificationCompat.InboxStyle();
    notificationBuilder.setStyle(inboxStyle);
    NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = notificationBuilder.build();
    notificationManager.notify(order.getId(), notification);`
...