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 b
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
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)
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
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)
This is an answer for anyone whose Android is too old to have volume
subcommand in media
command.
Thanks to Alex P's link, I got the inspiration from this guy's blog: http://ktnr74.blogspot.com/2014/09/calling-android-services-from-adb-shell.html
You can use service
command to call functions like void setStreamVolume(int streamType, int index, int flags, String callingPackage)
on your Android device. I've tried with my unrooted Android 5.1 device and it worked.
Usage: service [-h|-?]
service list
service check SERVICE
service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
i32: Write the integer INT into the send parcel.
s16: Write the UTF-16 string STR into the send parcel.
But the CODE
differs between Android versions. To find the code for setStreamVolume()
, first save the Bash script fron this gist, change its permission to execuatble, connect your device via ADB and run the script with audio
as argument:
$ ./get_android_service_call_numbers.sh audio
The script pulls info from Google and show you a list like this.
So we know the code for setStreamVolume()
is 4, since we know the number for STREAM_MUSIC is 3, we can set music volume to 7 by this command:
$ adb shell service call audio 4 i32 3 i32 7
The maximum music volume on my device is 0xF
, you can query yours with int getStreamMaxVolume(int streamType)
function:
$ adb shell service call audio 15 i32 3