Android自定义系统音量,Android adb命令设置和获取系统音量

时间:2024-10-08 08:05:58

1、查看audio的全部信息(各音频流音量,焦点,策略等)

dumpsys audio

2、设置音量并且显示音量UI

//stream 3表示多媒体,10表示音量值

media volume --show --stream 3 --set 10

3、音量调大调小

media volume --stream 3 --adj raise

media volume --stream 0 --adj lower

media volume --show --stream 3 --adj raise

media volume --show --stream 0 --adj lower

4、获取当前音量

media volume --stream 3 --get

5、直接调用Android接口设置音量

service call audio 7 i32 3 i32 10 i32 1

Here, the service call refers to IAudioService. Click here for more info.

7 is the function named setStreamVolume. It is the 7th in the list of functions in the interface IAudioService. Verify it here. (setStreamVolume takes 3 parameters streamType, index, flag)

i32 is to write the integer INT into the send parcel. (Alternatively we can make use of s16 for UTF-16 string)

3 is streamTypevalue. (Value 1 → phone, 3 → speaker, 4 → alarm, 6 → bluetooth)

1 is index value and 1 is flag value

参考文档:

/questions/124249/in-call-volume-root-modify?answertab=active#tab-top

/platform/frameworks/base/+/73e23e2/media/java/android/media/

6、控制播放暂停

media dispatch play

media dispatch pause

详细用法:

usage: media [subcommand] [options]

media dispatch KEY

media list-sessions

media monitor

media volume [options]

media dispatch: dispatch a media key to the system.

KEY may be: play, pause, play-pause, mute, headsethook,

stop, next, previous, rewind, record, fast-forward.

media list-sessions: print a list of the current sessions.

media monitor: monitor updates to the specified session.

Use the tag from list-sessions.

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

参考文档:

/platform/frameworks/base/+/android-5.1.1_r1/cmds/media/src/com/android/commands/media/?autodive=0%2F%2F%2F%2F

本文地址:/Sunxiaolin2016/article/details/108843716