2011-05-11 64 views
1

我用这个代码来调整音量的音量,但没有奏效我想改变ringertonevolume

int volume=23; 
audio.setStreamVolume(AudioManager.STREAM_RING,volume, AudioManager.FLAG_PLAY_SOUND|AudioManager.FLAG_ALLOW_RINGER_MODES);} 
+1

“没不工作“不是一个非常有用的描述。有没有错误信息?编辑您的问题以包含更多信息。 – Emyr 2011-05-11 13:09:50

回答

9

你不应该只是在音量设置为23,而不是你应该首先作出getStreamMaxVolume通话(流类型),以获得StreamType的最大音量,在这种情况下是铃声的音量。

例如,要将铃声的音量设置为最大,请执行此操作!

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

最新通报

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); 

确定。现在,我在家里,我可以尝试代码。在这里,你可以看到,streamMaxVolume给了我一个整数7.如果你试图将它设置为23太多。因此可以在setStreamVolume使用的可能值在我的情况是

0,1,2,3,4,5,6,7 最低< ----->最高

//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

那么我怎样才能调整通过编程的音量 – kannappan 2011-05-12 06:38:07

+0

做这行代码适合你?如果它工作不正常给另一个例子 – Rejinderi 2011-05-13 11:16:50

+0

雅我工作这行代码 – kannappan 2011-05-13 12:18:33