gpt4 book ai didi

android-8.0-oreo - Android O 不显示前台服务通知

转载 作者:行者123 更新时间:2023-12-04 07:25:06 27 4
gpt4 key购买 nike

根据文档,我在应用程序中进行了更改以使用 context.startForegroundService(Intent) 在后台启动服务然后调用startForeground像以前一样在服务中。

NotificationCompat.Builder notification = new 
NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.icon)
.setContentText("Content")
.setOngoing(true)
.setContentInfo("Info")
.setContentTitle("Title");
startForeground(1, notification.build());

这会在 Android N 设备上正确显示通知,但在 Android O 设备上它不会显示通知,它只显示新的“正在后台运行...点击以获取有关电池和数据使用情况的更多详细信息”

是否缺少让通知在 Android O 上正确显示的内容?

最佳答案

上面的答案对我不起作用。您必须创建 channel 才能工作,然后传递 channel ID。

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

String channelId = "some_channel_id";
CharSequence channelName = "Some Channel";
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
notificationManager.createNotificationChannel(notificationChannel);

然后使用相同的 cannelId 创建一个通知
new NotificationCompat.Builder(this, channelId)

关于android-8.0-oreo - Android O 不显示前台服务通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44702955/

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