gpt4 book ai didi

java - 有什么方法可以以编程方式在MIUI 10上启用锁定屏幕通知吗?

转载 作者:行者123 更新时间:2023-11-30 05:03:08 26 4
gpt4 key购买 nike

我正在创建一个消息传递应用程序,因此通知在我的应用程序中起着重要的作用。我已经创建了通知显示处理程序,通知在一台,Motorola,Samsung上正常运行,但在Mi设备上却没有。默认情况下,我的应用程序在MI设备(MIUI10)中禁用锁屏通知。但是,当我检查了诸如WhatsApp,Snapchat之类的流行应用程序的设置时,将启用所有选项,例如锁屏通知,声音,浮动通知。

我可以手动启用所有设置,但我想以编程方式进行设置,因此用户不需要这样做。
我尝试使用其方法setLockscreenVisibility()使用通知通道(适用于上述O设备),但此方法不起作用。

notificationChannel = new NotificationChannel(ChatSDKMessageChannel, name, NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setSound(soundUri, audioAttributes);
channel.enableVibration(true);


///
    显示通知的代码

公共无效createAlertNotification(上下文上下文,意图结果意图,字符串标题,字符串消息,位图largeIcon,int smallIconResID,Uri soundUri,int编号){

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


screenshot of notification setting of my demo app

screenshot of WhatsApp

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

最佳答案

也许您需要权限验证

关于java - 有什么方法可以以编程方式在MIUI 10上启用锁定屏幕通知吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57866224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com