Skip to content

Commit

Permalink
Fix integrated player crashing on Android 14 (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxr1998 authored Sep 3, 2023
1 parent bb22feb commit 322201e
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit 322201e

Please sign in to comment.