Android O-单行通知-类似于"Android系统-USB为该设备充电" [英] Android O - Single line Notification - like the "Android System - USB charging this device"

查看:246
本文介绍了Android O-单行通知-类似于"Android系统-USB为该设备充电"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想收到有关ForegroundService的持续通知,该通知需要尽可能小的位置.我喜欢"Android系统-USB为该设备充电"样式,但是我找不到任何示例来实现此目的.

I would like to have an ongoing notification for my ForegroundService that requires as small place as possible. I like the "Android System - USB charging this device" style, but I cannot find any example how to achieve this.

有人能指出我正确的方向吗?

Can anyone point me in the right direction?

如果为频道分配了重要性IMPORTANCE_MIN,则会将样式赋予通知.

The style is given to the notification if the channel is assigned the importance IMPORTANCE_MIN.

似乎没有办法使用内置样式的Android来通知IMPORTANCE_MINForegroundService一起使用.

It looks like there is no way to use Androids built in style for notifications of IMPORTANCE_MIN to be used with a ForegroundService.

这是IMPORTANCE_MIN的描述:

最低通知重要性:仅在折叠下方的阴影中显示.不应将其与Service.startForeground一起使用,因为前台服务应该是用户关心的东西,因此将其通知标记为最低重要性没有语义上的意义.如果您从Android版本Build.VERSION_CODES.O开始执行此操作,系统将显示有关您的应用在后台运行的优先级更高的通知.

Min notification importance: only shows in the shade, below the fold. This should not be used with Service.startForeground since a foreground service is supposed to be something the user cares about so it does not make semantic sense to mark its notification as minimum importance. If you do this as of Android version Build.VERSION_CODES.O, the system will show a higher-priority notification about your app running in the background.

推荐答案

要回答原始问题:

Android O上似乎没有内置的方法来获取ForegroundService的单行和正在进行的通知.可以尝试添加自定义设计,但是由于不同的手机具有不同的通知设计,因此该解决方案并不是一个很好的解决方案.

There seems to be no built-in way on Android O to get a single line, ongoing notification for a ForegroundService. One could try adding a custom design, but as different phones have different designs for notification, that solution is hardly a good one.

但是还是有希望的:)

Android P 上,将NotificationChannel中的IMPORTANCE_LOW中优先级为PRIORITY_LOW 的通知压缩为单个行,即使对于ForegroundService.是的!

On Android P the notification in a NotificationChannel of IMPORTANCE_LOW with a priority of PRIORITY_LOW is compacted to a single line even for a ForegroundService. Yeah!!

这篇关于Android O-单行通知-类似于"Android系统-USB为该设备充电"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆