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