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 integrated player crashing on Android 14 #1180

Merged
merged 3 commits into from
Sep 3, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jellyfin.mobile.player.interaction

import android.app.Application
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
Expand All @@ -9,6 +8,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Bitmap
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.core.graphics.drawable.toBitmap
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -38,7 +38,7 @@ import org.koin.core.component.inject
import java.util.concurrent.atomic.AtomicBoolean

class PlayerNotificationHelper(private val viewModel: PlayerViewModel) : KoinComponent {
private val context: Context = viewModel.getApplication<Application>()
private val context: Context = viewModel.getApplication()
private val appPreferences: AppPreferences by inject()
private val notificationManager: NotificationManager? by lazy { context.getSystemService() }
private val imageApi: ImageApi = get<ApiClient>().imageApi
Expand All @@ -62,7 +62,7 @@ class PlayerNotificationHelper(private val viewModel: PlayerViewModel) : KoinCom
}
}

@Suppress("DEPRECATION")
@Suppress("DEPRECATION", "LongMethod")
fun postNotification() {
val nm = notificationManager ?: return
val player = viewModel.playerOrNull ?: return
Expand All @@ -87,7 +87,8 @@ class PlayerNotificationHelper(private val viewModel: PlayerViewModel) : KoinCom

val notification = Notification.Builder(context).apply {
if (AndroidVersion.isAtLeastO) {
setChannelId(Constants.MEDIA_NOTIFICATION_CHANNEL_ID) // Set Notification Channel on Android O and above
// Set notification channel on Android O and above
setChannelId(Constants.MEDIA_NOTIFICATION_CHANNEL_ID)
setColorized(true)
} else {
setPriority(Notification.PRIORITY_LOW)
Expand Down Expand Up @@ -123,7 +124,12 @@ class PlayerNotificationHelper(private val viewModel: PlayerViewModel) : KoinCom
for (notificationAction in PlayerNotificationAction.values()) {
filter.addAction(notificationAction.action)
}
context.registerReceiver(notificationActionReceiver, filter)
ContextCompat.registerReceiver(
context,
notificationActionReceiver,
filter,
ContextCompat.RECEIVER_NOT_EXPORTED,
)
}
}

Expand Down