Android adb命令设置和获取系统音量

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

参考文档:
https://android.stackexchange.com/questions/124249/in-call-volume-root-modify?answertab=active#tab-top
https://android.googlesource.com/platform/frameworks/base/+/73e23e2/media/java/android/media/IAudioService.aidl
6、控制播放暂停

	media dispatch play
	media dispatch pause

详细用法:

usage: media [subcommand] [options]
       media dispatch KEY
       media list-sessions
       media monitor <tag>
       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

参考文档:
https://android.googlesource.com/platform/frameworks/base/+/android-5.1.1_r1/cmds/media/src/com/android/commands/media/Media.java?autodive=0%2F%2F%2F%2F

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunxiaolin2016

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值