前台通知不显示在通知栏中
Foreground notification not displaying in notification bar
通知通道的新代码在旧的和最新的奥利奥设备上工作正常,但是当我在 API 28(android P) 设备上测试时,它没有在通知中显示通知吧,这是我用来启动前台通知的行。
startForeground(NOTIFICATION_ID, notification);
如果您的目标是 Android 9.0(API 级别 28)
- 需要在清单中添加
FOREGROUND_SERVICE permission
。
Note: Apps that target Android 9.0 (API level 28) or higher and use
foreground services must request the FOREGROUND_SERVICE permission.
This is a normal permission, so the system automatically grants it to
the requesting app.
在清单中添加权限
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
通知通道的新代码在旧的和最新的奥利奥设备上工作正常,但是当我在 API 28(android P) 设备上测试时,它没有在通知中显示通知吧,这是我用来启动前台通知的行。
startForeground(NOTIFICATION_ID, notification);
如果您的目标是 Android 9.0(API 级别 28)
- 需要在清单中添加
FOREGROUND_SERVICE permission
。
Note: Apps that target Android 9.0 (API level 28) or higher and use foreground services must request the FOREGROUND_SERVICE permission. This is a normal permission, so the system automatically grants it to the requesting app.
在清单中添加权限
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />