I’m writing an app that’s meant to work on car radio and I would like to add a feature allowing to set the volume to certain level, to be specific – ducking it for safety reasons while reversing.
Unfortunately any of the methods from AudioManager
that work on my phone don’t work on the radio. Both devices run on Android 10 (can’t upgrade radio). Car radio model: uis8581 FYT.
I checked isVolumeFixed
from AudioManager
library, it returns false
on both devices, however my app acts on the radio as if isVolumeFixed
was true
. Description of isVolumeFixed.
What has been tried:
AudioManager
functions:
private AudioManager am;
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(AudioManager.STREAM_MUSIC, 2, 0);
and other variant:
private AudioManager am;
am.setStreamVolume(AudioManager.STREAM_MUSIC, 2, 0);
Works on the phone in both cases, doesn’t work on the radio.
-
AudioTrack.setVolume()
andMediaPlayer.setVolume()
according to this guide however I didn’t expect it to work because app should control system audio, it doesn’t play music by itself. Doesn’t work. -
Calling a key intent with shell commands with the code below:
public void sudo(String command) {
try{
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes(command+"n");
outputStream.flush();
outputStream.writeBytes("exitn");
outputStream.flush();
try {
su.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
outputStream.close();
}catch(IOException e){
e.printStackTrace();
}
}
sudo("input keyevent X");
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
164 --> "KEYCODE_MUTE"
Works on both devices.
sudo("media volume --show --stream 3 --set 11");
Works on the phone, doesn’t work on the radio.
sudo("am broadcast -a com.microntek.irkeyDown --ei keyCode 281");
Doesn’t work, however I didn’t expect it to work because there is no microntek
app/service on the radio. I tried it just in case.
-
Apps allegedly allowing to change the volume, specifically FCC Car Launcher according to that question and that one: https://github.com/d51x/KaierUtils (also uses
android.tw.john.TWUtil
package which seems to somehow control the volume). Both don’t work as well as other volume apps from Play Store. -
I reviewed the logs. Following messages emerged from what I could filter:
15:25:40 AS.AudioService: setStreamVolume(stream=4, index=0, calling=com.syu.ms)
15:25:40 AS.AudioService: setStreamVolume(stream=3, index=25, calling=com.syu.ms)
15:25:40 AS.AudioService: setStreamVolume(stream=1, index=7, calling=com.syu.ms
(these were logged multiple time repeatedly in the same miliseconds)
and
15:25:40 soundMute: ================>>> volume value: 19
That corresponds with the volume I set with physical buttons.
I’ve noticed that stock android on phone has gradation from 1 to 25 while on radio it goes up to 36.
Temporary solution is to use mute
key code (164 called with shell) or determining current volume with AudioManager
and decreasing/increasing it with loop using shell commands. Alas both options display the slider, first one turns the volume off insted ducking it as intended and the second one is not instant. I’m looking for more elegant way. Any help would be appreciated!