I want change the volume of ringertonevolume
i used this code to adjust volume but it didn't work
int volume=23;
audio.setStreamVolume(AudioManager.ST开发者_如何转开发REAM_RING,volume, AudioManager.FLAG_PLAY_SOUND|AudioManager.FLAG_ALLOW_RINGER_MODES);}
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);
精彩评论