Pse*_*328 17 android android-9.0-pie
我们调整了我们对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()
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我们只是创建通知然后调用startForeground.关于为什么这段代码会产生标题错误的任何想法?
侧注:Fabric Crashlytics显示此崩溃仅发生在运行Pie的像素设备(像素,像素xl,像素2,像素2 xl)上
编辑:我们的清单中有前台权限
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Run Code Online (Sandbox Code Playgroud)
小智 6
如此处背景服务限制所述,该应用程序/服务有五秒钟的调用时间startForeground(),如果该应用程序在该时限内未调用startForeground(),则系统将停止该服务并声明该应用程序为ANR。
有一些可能性:
startForeground()方法之前,您的前台服务都将被破坏/完成 。onCreate被调用,则将不调用该方法,而是onStartCommand将调用该方法。然后将您的逻辑onStartCommand移至调用startForeground()方法。startForeground 不能为0,否则也会导致崩溃。| 归档时间: |
|
| 查看次数: |
9499 次 |
| 最近记录: |