From 31c4bcc7b6a4d67e745a9e920a0de55f01d057e2 Mon Sep 17 00:00:00 2001 From: liupeng Date: Wed, 13 Nov 2024 10:16:17 +0800 Subject: [PATCH] fix: Fix crash issue on Android 14 --- library/src/main/AndroidManifest.xml | 2 ++ .../versionchecklib/v2/ui/VersionService.kt | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 5d805c2..27a904d 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -7,6 +7,7 @@ + = Build.VERSION_CODES.O && isRunOnForegroundService) { - startForeground( - NotificationHelper.NOTIFICATION_ID, - NotificationHelper.createSimpleNotification(this@VersionService) - ) + val notification = NotificationHelper.createSimpleNotification(this@VersionService) + val notificationId = NotificationHelper.NOTIFICATION_ID + // 指定服务类型 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) + } else { + startForeground(notificationId, notification) + } Thread.sleep(500) } isServiceAlive = true