-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back notification listener for permissions to get media sessions
- Loading branch information
Showing
15 changed files
with
235 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/src/main/kotlin/com/livetl/android/data/media/YouTubeNotificationListenerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.livetl.android.data.media | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.media.session.MediaSessionManager | ||
import android.service.notification.NotificationListenerService | ||
import android.service.notification.StatusBarNotification | ||
import androidx.core.app.NotificationManagerCompat | ||
import androidx.core.content.getSystemService | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class YouTubeNotificationListenerService : NotificationListenerService() { | ||
|
||
@Inject | ||
lateinit var youTubeSessionService: YouTubeSessionService | ||
|
||
override fun onNotificationPosted(sbn: StatusBarNotification) { | ||
super.onNotificationPosted(sbn) | ||
|
||
if (sbn.packageName != YOUTUBE_PACKAGE_NAME) { | ||
return | ||
} | ||
|
||
val mediaSessionManager = getSystemService<MediaSessionManager>() ?: return | ||
|
||
val component = ComponentName(this, YouTubeNotificationListenerService::class.java) | ||
val sessions = mediaSessionManager.getActiveSessions(component) | ||
youTubeSessionService.onActiveSessionsChanged(sessions) | ||
} | ||
|
||
companion object { | ||
fun isNotificationAccessGranted(context: Context): Boolean = | ||
NotificationManagerCompat.getEnabledListenerPackages(context) | ||
.any { it == context.packageName } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.