Unofficial-Whisperplay-Fling-Helpline / wp

Placeholder repo so I can have a bug tracker.
0 stars 0 forks source link

Background start not allowed when trying to cast while my application is not open #5

Open petergoczan-hotstar opened 1 day ago

petergoczan-hotstar commented 1 day ago

Hi,

I'm implementing casting to FireStick in my project, and it kind-of works, but when my app is not already open on FireStick when I'm trying to start the casting from mobile, nothing happens, and I'm getting the following warning: Background start not allowed : service Intent { flg=0x10000000 cmp=my.package.name/my.package.fling.FlingPlayerService } to my.package.name/my.package.fling.FlingPlayerService from pid=... uid=... pkg=com.amazon.whisperlink.core.android startFg?=false

I need a custom app for Firestick because I don't want to play publicly available URLs in there. Am I doing something wrong?

My FireStick android version is Fire OS 7.6.7.9, type is Fire TV Stick Lite

Here is my FlingPlayerService implementation:

`@AndroidEntryPoint class FlingPlayerService : MediaPlayerHostService() {

@Inject lateinit var flingPlayerManager: FlingPlayerManager

override fun onBind(intent: Intent?): IBinder? = null

override fun onCreate() {
    super.onCreate()
    startForegroundWithNotification()
}

override fun createServiceImplementation(): CustomMediaPlayer = FlingPlayer(this, flingPlayerManager)

override fun getPlayerId(): String = "my.package.name.custom.player"

private fun startForegroundWithNotification() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
        val notificationManager = NotificationManagerCompat.from(this)
        val channel = NotificationChannelCompat.Builder("channel_id", NotificationManagerCompat.IMPORTANCE_DEFAULT)
            .setName("Player")
            .build()
        notificationManager.createNotificationChannel(channel)
        val notification = NotificationCompat.Builder(this, "channel_id")
            .setSmallIcon(R.drawable.logo)
            .setContentTitle("Player")
            .build()
        startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
    } else {
        val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            val channel = NotificationChannel("channel_id", "Player", NotificationManager.IMPORTANCE_DEFAULT)
            notificationManager.createNotificationChannel(channel)
        }
        val notification = NotificationCompat.Builder(this, "channel_id")
            .setSmallIcon(R.drawable.logo)
            .setContentTitle("Player")
            .build()
        startForeground(1, notification)
    }
}

}`

petergoczan-hotstar commented 17 hours ago

Solved this by adding <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />