Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix crash issue on Android 14 #364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>

<application
android:allowBackup="true"
Expand Down Expand Up @@ -34,6 +35,7 @@
<service
android:name=".v2.ui.VersionService"
android:exported="false"
android:foregroundServiceType="dataSync"
android:priority="1000" />

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.allenliu.versionchecklib.v2.ui
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import androidx.annotation.WorkerThread
Expand Down Expand Up @@ -302,10 +303,14 @@ class VersionService : Service() {
BuilderManager.doWhenNotNull {
//https://issuetracker.google.com/issues/76112072
if (Build.VERSION.SDK_INT >= 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
Expand Down