I want change the volume of ringertonevolume

前端 未结 1 1176
眼角桃花
眼角桃花 2021-02-11 09:27

i used this code to adjust volume but it didn\'t work

int volume=23;
audio.setStreamVolume(AudioManager.STREAM_RING,volume, AudioManager.FLAG_PLAY_SOUND|AudioMan         


        
相关标签:
1条回答
  • 2021-02-11 10:14

    you should not just set the volume to 23 instead you should first make a call to getStreamMaxVolume(StreamType) to get the max volume possible for the StreamType which in this case is the ringer's volume.

    for example, to set the ringer's volume to max you do this!

    audioManager.setStreamVolume(AudioManager.STREAM_RING, audioManager.getStreamMaxVolume(AudioManager.STREAM_RING), FLAG_ALLOW_RINGER_MODES|FLAG_PLAY_SOUND);
    

    UPDATES

        int streamMaxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
        Toast.makeText(this, Integer.toString(streamMaxVolume), Toast.LENGTH_LONG).show(); //I got 7
        audioManager.setStreamVolume(AudioManager.STREAM_RING, streamMaxVolume, AudioManager.FLAG_ALLOW_RINGER_MODES|AudioManager.FLAG_PLAY_SOUND);
    

    ok. now that i am at home i can try out codes. here as you can see, streamMaxVolume gives me a integer of 7. if you try to set it to 23 its way too much. so the possible values you can use in setStreamVolume in my case is

    0, 1, 2, 3, 4, 5, 6, 7 Lowest <-----> Highest

    //set to lowest ->
    audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, AudioManager.FLAG_ALLOW_RINGER_MODES|AudioManager.FLAG_PLAY_SOUND);
    
    //set to loudest ->
    audioManager.setStreamVolume(AudioManager.STREAM_RING, 7, AudioManager.FLAG_ALLOW_RINGER_MODES|AudioManager.FLAG_PLAY_SOUND);
    
    0 讨论(0)
提交回复
热议问题