Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置android应用程序的音量_Android - Fatal编程技术网

设置android应用程序的音量

设置android应用程序的音量,android,Android,为了让用户控制音量,我的android应用程序有一个由滑块组成的菜单,当拖动时,该滑块提供从0到10的int值。在获得一个值后,我必须将音量设置为用户选择的相应值,这是我不知道要实现的部分,我想了解一下 使用该类。基本上,代码如下所示: AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(streamType, volume

为了让用户控制音量,我的android应用程序有一个由滑块组成的菜单,当拖动时,该滑块提供从0到10的int值。在获得一个值后,我必须将音量设置为用户选择的相应值,这是我不知道要实现的部分,我想了解一下

使用该类。基本上,代码如下所示:

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(streamType, volume, flags);
问题在于,设备的体积不一定像滑块中那样从0映射到10。在我的模拟器上,它是从0到7。所以你需要做的是
getStreamMaxVolume(…)
知道你的最大值是多少,然后计算出你的值作为它的一部分。例如,如果用户从10个卷中选择第8个卷,这相当于0.8*7=5.6,您应该将其四舍五入为7个卷中的6个卷

“流”指的是振铃器音量、通知音量、音乐音量等。如果要更改振铃器的音量,需要确保所有命令都有
AudioManager.stream\u RING
作为流类型