【发布时间】:2019-03-31 13:50:24
【问题描述】:
我们调整了 Oreo 的持续通知,效果很好。现在,仅在 Pie 上(不在 Oreo 设备上发生),我们得到了标题错误。我缺少的 Pie 中的前台服务有什么变化吗?
这是前台服务的 onCreate 代码 ->
override fun onCreate() {
super.onCreate()
val notification: Notification = NotificationCompat.Builder(this, packageName)
.setSmallIcon(R.drawable.status_notification_icon)
.setContentTitle(getString(R.string.ongoing_notify_temp_title))
.setContentText(getString(R.string.ongoing_notify_temp_message))
.setGroup(AppConstants.NOTIFICATION_GROUP_ONGOING)
.setColor(ContextCompat.getColor(this, R.color.custom_blue))
.build()
startForeground(ONGOING_NOTIFY_ID, notification)
appSettings = AppSettings(this)
weatherLookUpHelper = WeatherLookUpHelper()
MyRoomDatabase.getInstance().invalidationTracker.addObserver(onChange)
retrieveCurrentLocation()
createAlarmManager()
}
如您所见,我们只是创建通知,然后调用 startForeground。关于为什么此代码会生成标题错误的任何想法?
旁注:Fabric Crashlytics 显示此崩溃仅发生在运行 Pie 的像素设备(像素、像素 xl、像素 2、像素 2 xl)上
编辑:我们确实在清单中拥有前台权限
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
【问题讨论】:
-
你的manifest里有这个权限吗
Manifest.permission.FOREGROUND_SERVICE -
@MayRestinPeace 是的,我们这样做
-
这个问题你解决了吗?
-
@knowledgeDrilling 不幸的是没有。从那以后我已经换了工作,我现在正在进行的项目没有这个问题,所以我怀疑我会跟进这个问题。对不起:(