davidliu
Committed by GitHub

Add camera/mic service types to sample foreground service (#405)

* Add camera/mic service types to sample foreground service

* spotless
... ... @@ -4,8 +4,12 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission
android:name="android.permission.BLUETOOTH"
... ... @@ -17,7 +21,7 @@
<application>
<service
android:name="io.livekit.android.sample.service.ForegroundService"
android:foregroundServiceType="mediaPlayback"
android:foregroundServiceType="mediaPlayback|camera|microphone"
android:exported="false" />
</application>
... ...
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.livekit.android.sample.service
import android.app.NotificationChannel
... ... @@ -11,9 +27,15 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
/**
* A foreground service is required for screen capture on API level Q (29) and up.
* This a simple default foreground service to display a notification while screen
* capturing.
* A foreground service will keep the app alive in the background.
*
* Beginning with Android 14, foreground service types are required.
* This service declares the mediaPlayback, camera, and microphone types
* in the AndroidManifest.xml.
*
* This ensures that the app will continue to be able to playback media and
* access the camera/microphone in the background. Apps that don't declare
* these will run into issues when trying to access them from the background.
*/
open class ForegroundService : Service() {
... ...