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.

ڈیولپرز پر واپس

Applies to: utd_audio_room_kit 3.14.1 with utd_media_client 2.9.9

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.

The kits published today (utd_audio_room_kit 3.14.1, utd_live_room_kit 3.11.0, utd_media_client 2.9.9) do not start a foreground service for you. A built-in one, with a configurable notification, is planned for a later utd_media_client release; until it is published, your app owns the service.

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 کے ساتھ تعمیر کے لیے تیار ہیں؟

اپنا اکاؤنٹ بنائیں، اپنے ماسٹر والٹ کو فنڈ کریں، اور جن سروسز کی ضرورت ہے انہیں آن کریں۔