【发布时间】:2019-02-10 15:19:58
【问题描述】:
当启动 IntentService 在后台上传文件时,我想通过从我的服务内部调用 showNotification() 向用户显示上传正在进行的通知:
private void showNotification() {
Notification notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_cloud_upload_black_24dp)
.setWhen(System.currentTimeMillis())
.setContentTitle("Uploading")
.setContentText("Your upload is in progress.")
.setOngoing(true)
.build();
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
现在我的问题是:通知出现在锁定屏幕上,但屏幕解锁时不在状态栏中。我错过了什么?
部署目标是 API 级别 24,因此缺少 NotificationChannel 不应该是原因。
【问题讨论】:
-
通知通道添加在api级别>26,对于oreo及更高版本,意味着您的代码正在工作以在锁定屏幕中显示通知,您是否在oreo设备上测试?
-
我已经添加了答案,请尝试并告诉我:)
标签: android notifications statusbar intentservice