How to programmatically set the volume on a car radio – Android app in Java

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:

  1. 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.

  1. AudioTrack.setVolume() and MediaPlayer.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.

  2. 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.

  1. 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.

  2. 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!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật