I'm diving into new project which is using a microphone input to transmit voice. Audio is recorded by Service
, capturing may be started from UI (e.g. Activity
), but also from server side (some kind of eavesdropping) or by broadcast from another app. Feature works well across all versions of Android.
Now I've got task to handle some keys (KeyEvent
), even when app is in background, but above mentioned foreground service is running. So I've made AccessibilityService
with overriden onKeyEvent(KeyEvent event)
, checking inside is service running and handling proper keys if needed. This feature works fine also.
BUT I've just noticed strange behavior on Android 10 - silence from mic when AccessibilityService
is turned on... When I'm turing it off mic starts working. On Android 9 and below audio capture works always no matter of on/off state.
I've found guide in docs with some info about changed behavior of handling audio input and dispatching it, but I don't see any related section to my situation. Audio capture feature and accessibility service belong to one app and this service is needed only for keys handling. So the question is why my service breaks down mic on Android 10 and how I can prevent this?
As a bonus - XML with configuration
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes=""
android:accessibilityFeedbackType="feedbackSpoken|feedbackHaptic"
android:accessibilityFlags="flagRequestFilterKeyEvents"
android:canRequestFilterKeyEvents="true"
android:canRetrieveWindowContent="false"
android:description="@string/accessibility_permission_desc"
android:notificationTimeout="25"
android:packageNames="my.package.name"
android:settingsActivity="" />