Developer guide

Keeping the microphone alive in the background (Android)

Why a speaker who switches apps goes silent on Android, and what your app has to declare.

رجوع لمطوّري UTD Stream

Applies to: utd_audio_room_kit 4.2.1 with utd_media_client 2.12.1

Since Android 9 the system silences the microphone of an app that is in the background and has no foreground service. Since Android 14 that service must be of the microphone type and the app must hold the FOREGROUND_SERVICE_MICROPHONE permission. Without it, a user on a seat who leaves your app for a few seconds comes back to a dead microphone. Listening is not affected.

utd_audio_room_kit 4.x starts a microphone foreground service for you (audio rooms only, on by default, configurable with UTDAudioRoomConfig.foregroundService; your Play Console needs the Microphone foreground-service declaration). utd_live_room_kit does not start one: your app owns it. utd_media_client 2.10.0 and later exposes UtdmForegroundService for apps that do it themselves; it never starts by itself.

What your app declares

android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application ...>
  <service
      android:name=".VoiceRoomService"
      android:foregroundServiceType="microphone"
      android:exported="false" />
</application>
  • Start your service while the app is in the foreground, when the user takes a seat, and stop it when they leave the seat or the room. Android refuses to start a microphone foreground service from the background.
  • The service shows a persistent notification; tell the user why ("Your microphone is on").
  • On iOS the equivalent is the Audio background mode: enable Background Modes, then Audio, AirPlay and Picture in Picture, in Xcode.
  • Check the Play Console foreground-service declaration for the microphone type before you publish.

جاهز تبني مع UTD؟

أنشئ حسابك، اشحن محفظتك الأم، وشغّل الخدمات التي تحتاجها.