Java 有没有办法以编程方式在MIUI 10上启用锁屏通知?

Java 有没有办法以编程方式在MIUI 10上启用锁屏通知?,java,android,Java,Android,我正在创建一个消息应用程序,因此通知在我的应用程序中起着重要作用。我已经创建了通知显示处理程序,通知在one plus、摩托罗拉、三星上运行良好,但在Mi设备上运行不好。默认情况下,在MI设备(MIUI10)中禁用我的应用程序的锁屏通知。但当我检查WhatsApp等流行应用程序的设置时,Snapchat所有选项都已启用,如锁屏通知、声音、浮动通知 我可以手动启用所有设置,但我希望以编程方式启用,这样用户就不需要这样做。 我尝试使用通知通道(针对上述设备)的方法setLockscreenVisib

我正在创建一个消息应用程序,因此通知在我的应用程序中起着重要作用。我已经创建了通知显示处理程序,通知在one plus、摩托罗拉、三星上运行良好,但在Mi设备上运行不好。默认情况下,在MI设备(MIUI10)中禁用我的应用程序的锁屏通知。但当我检查WhatsApp等流行应用程序的设置时,Snapchat所有选项都已启用,如锁屏通知、声音、浮动通知

我可以手动启用所有设置,但我希望以编程方式启用,这样用户就不需要这样做。 我尝试使用通知通道(针对上述设备)的方法
setLockscreenVisibility()
,但没有成功

notificationChannel = new NotificationChannel(ChatSDKMessageChannel, name, NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setSound(soundUri, audioAttributes);
channel.enableVibration(true);
显示通知的代码:


 public void createAlertNotification(Context context, Intent resultIntent, String title, String message, Bitmap largeIcon, int smallIconResID, Uri soundUri, int number){

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        Notification.Builder builder =
                new Notification.Builder(context)
                        .setContentTitle(title)
                        .setContentText(message)
                        .setSmallIcon(smallIconResID)
                        .setVibrate(new long[]{0, 250, 100, 250})
                        .setSound(soundUri)
                        .setNumber(number)
                        .setContentIntent(pendingIntent)
                        .setTicker(title + ": " + message)
                        .setPriority(Notification.PRIORITY_HIGH);

        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (largeIcon != null) {
            builder.setLargeIcon(ImageUtils.scaleImage(largeIcon, (int) (context.getResources().getDisplayMetrics().density * 48)));
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setColor(ChatSDK.config().pushNotificationColor);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Create the NotificationChannel, but only on API 26+ because
            // the NotificationChannel class is new and not in the support library
            builder.setChannelId(ChatSDKMessageChannel);

            CharSequence name = context.getString(R.string.app_name);
            String description = context.getString(R.string.push_channel_name);

            NotificationChannel channel = new NotificationChannel(ChatSDKMessageChannel, name, NotificationManager.IMPORTANCE_HIGH);
            channel.enableVibration(true);
            channel.setDescription(description);

            if (notificationManager != null) {
                notificationManager.createNotificationChannel(channel);
            }

        }


        Notification notification = builder.build();

        notification.flags = Notification.FLAG_AUTO_CANCEL ;

        notificationManager.notify(MESSAGE_NOTIFICATION_ID, notification);

        wakeScreen(context);
    }

我的演示应用程序的通知设置屏幕截图:

WhatsApp截图:


我需要为我的应用程序启用所有通知选项,就像WhatsApp和snapchat一样。

我认为目前不可能。但是,您可以通过显示一些弹出对话框和访问设置的按钮来要求用户启用它。@RahulKhurana您可以检查Viber、Snapchat、,WhatsApp所有选项都已启用。是的,这些是在操作系统级别硬编码的白名单应用程序,用于授予某些特定权限。@RahulKhurana,因此我们无法对不受欢迎的应用程序执行此操作。是的,用户需要手动启用它。