如何在小米(MIUI 10 Global)上启用抬头通知

时间:2019-04-16 15:25:45

标签: android push-notification android-push-notification xiaomi heads-up-notifications

如何在小米设备上以编程方式启用抬头通知? 某些应用程序(例如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);`

0 个答案:

没有答案