【问题标题】:MIUI heads up notification not workingMIUI抬头通知不起作用
【发布时间】:2018-08-12 08:16:00
【问题描述】:

我正在努力让我的通知显示抬头或窥视,因为它也被称为。

它适用于现有的 Android 和 Lineage OS API 21-26

需要做什么才能让它在 MIUI 8 中运行?

该应用拥有所有通知权限。

这是我的通知代码示例:

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());
}

【问题讨论】:

  • 您是否尝试添加振动模式?
  • 嗨,是的,我有。我添加了上面代码的示例。该代码会在 Stock android 和 LineageOS 上生成提示,但不会在 MIUI 上生成...是的,所有通知权限都已授予应用程序。
  • 尝试添加 setDefaults(Notification.DEFAULT_ALL)
  • 我已经添加了 MIUi 的解决方案,请检查

标签: android notifications android-notifications heads-up-notifications miui


【解决方案1】:

您可以通过两种方式做到这一点。

转到:

  1. 设置

  2. 已安装的应用(迁移到您的应用)

  3. 选择您的应用并转到通知(切换优先级并切换浮动通知)

或者,创建一个远程视图(您自己的布局在 res/layout 中)并设置customHeadsUpNotification

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

 notification_builder.createHeadsUpContentView(remoteViews);

完成这些更改后不要忘记更改 notification_id。

【讨论】:

  • 谢谢!我第一次能够在 MIUI 上触发单挑。我会看看现在重建我的所有通知以使用 RemoveViews 是否有意义。
  • createHeadsUpContentView(remoteViews) 不将 remoteViews 作为参数。在 miui 10 上它也不适合我。你能帮忙@santanu-sur
猜你喜欢
  • 2023-03-22
  • 1970-01-01
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 2016-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多