Fix cheat import not working on Android 14 devices

This commit is contained in:
Rafael Caetano 2023-12-28 10:57:53 +00:00
parent 6d180774cd
commit 2e505830ec
3 changed files with 20 additions and 3 deletions

View File

@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<application
android:name=".MelonDSApplication"
@ -130,5 +131,10 @@
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="remove" />
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
</application>
</manifest>

View File

@ -1,7 +1,9 @@
package me.magnum.melonds.common.workers
import android.content.Context
import android.content.pm.ServiceInfo
import android.content.res.AssetFileDescriptor
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.core.net.toUri
@ -122,7 +124,10 @@ class CheatImportWorker @AssistedInject constructor(
.setProgress(100, progress, indeterminate)
.build()
return ForegroundInfo(NOTIFICATION_ID_CHEATS_IMPORT, notification)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(NOTIFICATION_ID_CHEATS_IMPORT, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
} else {
ForegroundInfo(NOTIFICATION_ID_CHEATS_IMPORT, notification)
}
}
}

View File

@ -1,6 +1,8 @@
package me.magnum.melonds.common.workers
import android.content.Context
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.hilt.work.HiltWorker
@ -45,6 +47,10 @@ class RetroAchievementsSubmissionWorker @AssistedInject constructor(
.setSmallIcon(R.drawable.ic_melon_small)
.build()
return ForegroundInfo(NOTIFICATION_ID_ACHIEVEMENT_SUBMISSION, notification)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(NOTIFICATION_ID_ACHIEVEMENT_SUBMISSION, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
} else {
ForegroundInfo(NOTIFICATION_ID_ACHIEVEMENT_SUBMISSION, notification)
}
}
}