override fun onStartCommand()

in app/src/main/java/com/amazonaws/services/chime/sdkdemo/service/ScreenCaptureService.kt [41:74]


    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        if (isOSVersionAtLeast(Build.VERSION_CODES.O)) {
            val channel = NotificationChannel(
                CHANNEL_ID,
                CHANNEL_NAME,
                NotificationManager.IMPORTANCE_DEFAULT
            )
            notificationManager.createNotificationChannel(channel)
        }

        if (isOSVersionAtLeast(Build.VERSION_CODES.Q)) {
            startForeground(
                SERVICE_ID,
                NotificationCompat.Builder(this, CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(getString(R.string.screen_capture_notification_tile))
                    .setContentText(getText(R.string.screen_capture_notification_text))
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .build(),
                ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
            )
        } else {
            startForeground(
                SERVICE_ID,
                NotificationCompat.Builder(this, CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(getString(R.string.screen_capture_notification_tile))
                    .setContentText(getText(R.string.screen_capture_notification_text))
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .build()
            )
        }
        return START_STICKY
    }