代码之家  ›  专栏  ›  技术社区  ›  eben80

MIUI抬头通知不工作

  •  4
  • eben80  · 技术社区  · 7 年前

    我很难让我的通知显示平视或偷看,因为它也被称为。

    它与股票Android和沿袭操作系统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());
    }
    
    1 回复  |  直到 7 年前
        1
  •  4
  •   Pang Ajmal PraveeN    7 年前

    您可以通过两种方式来实现这一点。

    去:

    1. 设置

    2. 已安装的应用程序(迁移到你的应用程序)

    3. 选择你的应用程序并转到通知( 打开优先级并打开浮动通知 )

    或者,创建远程视图(您自己的布局 资源/布局 )和设置 customHeadsUpNotification

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

    进行这些更改后,不要忘记更改notification\u id。

    推荐文章