ADB命令来设置音量?

Los*_*ost 2 android adb

是否有任何Adb命令将音量设置为特定值?我知道我们可以做

adb shell input keyevent 
Run Code Online (Sandbox Code Playgroud)

对于音量上下,但我想将其设置为特定值。如果我更改它的数据库,那么我必须重新启动设备以反映更改,所以我不想走那条路。是否没有任何API可以更改值而无需重新启动它并且不必依赖Volume Up和Down?

Xio*_*caL 6

media shell命令也可以使用:

media volume:  the options are as follows: 
    --stream STREAM selects the stream to control, see AudioManager.STREAM_*
                    controls AudioManager.STREAM_MUSIC if no stream is specified
    --set INDEX     sets the volume index value
    --adj DIRECTION adjusts the volume, use raise|same|lower for the direction
    --get           outputs the current volume
    --show          shows the UI during the volume change
examples:
    adb shell media volume --show --stream 3 --set 11
    adb shell media volume --stream 0 --adj lower
    adb shell media volume --stream 3 --get
Run Code Online (Sandbox Code Playgroud)

第一个示例可能是您要查找的示例(但在询问时可能不存在)


小智 5

对于那些对 XioRCal 提供的答案感到困惑的人,请使用adb shell cmd media_session代替,adb shell media因为它已在 Android 11 和 12 中删除。

参考:尝试通过 ADB 控制设备音量时出现“媒体:无法访问或未找到”错误