ADB Command to set volume?

2019-01-29 06:20发布

Is there any Adb command to set the volume to a particular value? I know that we can do

adb shell input keyevent 

for volume up and down but i want to set it to a particular value. If I change it it DB then I have to reboot the device for the changes to be reflected so i do not want to go that path. Isn't there any API where I can change the value without having to restart it and having to be dependent on Volume up and Down?

标签: android adb
3条回答
再贱就再见
2楼-- · 2019-01-29 06:46

I have used the service call audio test to set the volume on an android 2.3 device. In order to be more generic you need to research IBinder and the transaction number.

To find out what you want:

Adb shell service list packages

  • this will tell you the package file you need to look at for a service (I.e Bluetooth - com.Bluetooth.IBluetooth)

Search for the service class and 'transaction' online ("com.Bluetooth.Ibluetooth transaction")

Find the source files and find the Ibinder transaction details. This will be followed by the details of the input parameters.

I.e the first transaction on Bluetooth is .is enabled(). There are no input parameters

To use it send:

Adb shell service call Bluetooth 1

It should return a parcel containing the answer.

Remember: - I think it is only for rooted devices - the transaction number you find has an offset of 1 (transaction 0 is called with service call 'service' 1) - There are two types of input: i32 for integer or s16 for string

To set the audio there are three input integers for set volume (transaction 6)

To use it send:

Adb shell service call 7 i32 3 i32 15 i32 0 This will set the media volume to 15 (default number of levels for media audio is 15)

查看更多
趁早两清
3楼-- · 2019-01-29 06:47

On a rooted phone you can call setMasterVolume() with service call audio <code> i32 <volume>. The codes are version specific. Let's say you want to set volume to 50% on a KitKat device. The command will be:

service call audio 9 i32 50
查看更多
狗以群分
4楼-- · 2019-01-29 07:07

media shell command can also be used:

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

The first example is probably the one you were looking for (but it probably didn't exist at the time of asking)

查看更多
登录 后发表回答