SilentLucidity
SilentLucidity

Reputation: 410

Set and detect mono audio programmatically in Android (Accessibility)

Android allows me to set combine audio channels into a single, mono channel. It's in accessibility settings, takes to much time (imo). So I want to set it programmatically (or through tasker, Idc) but I can't find it inside the Android accessibility API documentation. I'm not sure if it's there, somewhere else or nowhere. Can someone help me find a way to detect if the settings is available and how to set it.

Thanks in advance!

The picture of the settings

Upvotes: 5

Views: 1749

Answers (4)

gstjee
gstjee

Reputation: 11

via reflection below worked more me:

                try {
                    boolean setMono = true;
                    Class<?> audioSystemClass = Class.forName("android.media.AudioSystem");
                    @SuppressLint("SoonBlockedPrivateApi") Method setMasterMonoMethod = audioSystemClass.getDeclaredMethod("setMasterMono", boolean.class);
                    Log.d(TAG, "setMasterMonoMethod returned: "+ (int) setMasterMonoMethod.invoke(null, setMono));
                } catch (Exception e) {
                    Log.e(TAG, "Error setting audio to mono: " + e.getMessage(), e);
                }

source for above class: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/media/java/android/media/AudioSystem.java

Upvotes: 1

color color
color color

Reputation: 1

Here is the command to set mono: settings put system master_mono 1

I decompiled that app David mentioned above, and found it.

Upvotes: 0

SilentLucidity
SilentLucidity

Reputation: 410

This app allows me to toggle it as an tile; but I think root is required. https://play.google.com/store/apps/details?id=it.simonesestito.ntiles

Upvotes: 0

David
David

Reputation: 33

So far I have not been able to find anything that can do this (on my unrooted Phone) programmatically.

I ended up using AutoInput to scroll down after opening Accessibility Settings with the task of that same name, then tapping the toggle for Mono Audio. Keep in mind to wait ~350ms or more between the actions to wait for things to occur (less issues with AutoInput not working properly) if you don't have a very fast device.

Secure Settings might be able to modify this, but rooting my phone for that one thing is not worth it.

Upvotes: 1

Related Questions