#android #push-notification #android-push-notification #xiaomi #heads-up-notifications
#Android #push-уведомление #android-push-уведомление #xiaomi #предупреждения-уведомления
Вопрос:
Как программно включить уведомления о предупреждениях на устройствах 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);`
Комментарии:
1. Он должен работать с помощью NotificationManager. ВАЖНОСТЬ ВЫШЕ, чем у других мобильных телефонов. Я не знаю, почему это не работает в Xiaomi! У меня такая же проблема
2. Есть сообщения, которые я не смог проверить, но в основном они утверждают, что китайские производители телефонов «записывают» популярные приложения, такие как WhatsApp, Telegram и т. Д., В то время как они ограничительно блокируют все другие приложения, когда дело доходит до определенных разрешений. Приложение Telegram для Android с открытым исходным кодом на Github, и, похоже, они даже не используют
ACCESS_NOTIFICATION_POLICY
, как многие предполагают, SO в отношении проблемы, которую вы описываете.