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?
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)
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)
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
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 - a SO question.
Tried with my un-rooted 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 from this gist, change its permission to executable, connect your device via ADB and run the script with audio as argument:
$ ./get_android_service_call_numbers.sh audio
(EDIT: https://github.com/T-vK/android-svc does that script.)
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
For those of you struggling with the answer provided by XioRCal, use adb shell cmd media_session instead of adb shell media as it has been removed in Android 11 and 12.
Reference: "media: inaccessible or not found" error when attempting to control device volume via ADB
In android 12 or later, can use cmd media_session shell cmd.
below is the usage: (need replace some media to cmd media_session)
usage: media_session [subcommand] [options]
media_session dispatch KEY
media_session dispatch KEY
media_session list-sessions
media_session monitor <tag>
media_session volume [options]
media_session dispatch: dispatch a media key to the system.
KEY may be: play, pause, play-pause, mute, headsethook,
stop, next, previous, rewind, record, fast-forword.
media_session list-sessions: print a list of the current sessions.
media_session monitor: monitor updates to the specified session.
Use the tag from list-sessions.
media_session 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
Related
I'm trying to track devices, SIMs and airtime cards for test purposes. I have multiple devices plugged into a computer and since the recent update to Android 12, I am not able to get the device IMEI. The IMEI is basically the device's FCC-required serial number and can be obtained from the UI with relative ease, but how can I obtain it via ADB or in some automated method on multiple devices from multiple carriers and OEMs?
Prior to Android 12 FEB patch, I would use service call iphonesubinfo 1 or service call iphonesubinfo 4. But unfortunately after the update I receive back Result: Parcel(ffffffffc ffffffff 00000000 '................') whereas before I would receive a parcel containing the IMEI for processing via script.
Is there a way to get IMEI on Android 12+? I am trying to stay away from using an app. This is a simple thing, from a privileged user (adb shell). It seems like a basic necessity for tracking and logistics purposes.
This command works to obtain IMEI. It works by pressing the dialer key, then typing *#06#, then parsing the text on screen to find the IMEI Label and the next element which contains the actual IMEI. Finally it parses that element by removing all before text=" and all after ".
adb shell "imei=$(input keyevent KEYCODE_CALL;sleep 1;input text '*#06#'; uiautomator dump --compressed /dev/stdout|sed s/\>\<\/\\n/g|grep -A1 IMEI|tail -n1|sed -e 's/.*text=\"//' -e 's/\".*//'); echo ${imei}"
to get just the 16-digit IMEI without checksum, replace the final echo statement with echo ${imei:0:16}
I found a good solution for Samsung One UI
First, run the About menu
adb shell am start -a com.android.settings.ACTION_DEVICE_INFO_SETTINGS
Then dump the UI
adb shell uiautomator dump
View the dump file
adb shell cat /sdcard/window_dump.xml
The IMEI1 in the <node index="12" and IMEI 2 in <node index="13"
I have a problem when sending DTMF events inside of an active call.
I am using adb shell input text #0123* to send DTMF tones. This was working good so far for older Android versions. Starting from Android 11 (I didn't check 12 yet), special characters * and # are not working anymore and sending 8 and 3 instead.
If I am sending the text at other text fields, the special chars are formatted correctly, the error is only occurring inside the call application when having an active call and trying to send DTMF tones via dialpad.
Edit:
I tried sending with ' escaped:
User:~$ adb -s RF8N31NZ5SK shell
x1s:/ $ input text '#*'
x1s:/ $
But result is the same:
Edit-2:
It looks like dialer is not allowing special chars anymore on Android >= 11. I managed to do it via keyevents KEYCODE_POUND and KEYCODE_STAR:
User:~$ adb -s RF8N31NZ5SK shell
x1s:/ $ input keyevent KEYCODE_POUND
x1s:/ $ input keyevent KEYCODE_STAR
x1s:/ $
You can try adding apostrophe to surround text to sent because # character is used for comments on Android shell :
adb shell input text '#1234*'
It worked on my side with Android 11
You can escape the hash character and place the whole input text in double quotes:
adb shell input text "\#1234*"
Note: In my tests I had to use double quotes, single quotes were not working, with single quotes the typed text was \#1234*. But this may depend on the used terminal/platform for executing the whole command (in my case Windows 10 command-line/cmd.exe).
This commands works for me and
I want to input swipe commands back to back using a c program and adb shell to my android device .
But the lag between the commands is preventing me from achieving my goal.
Is there anyway to reduce this lag??
You can record some input and repeat it directly.
For example:
Record:
cat /dev/input/event0 > inputdata
Replay:
cat inputdata > /dev/input/event0
To find the correct event number you can use the getevent -p command.
There is no "lag between the commands". The input command is a java application and it takes about a second (depending on your device) to launch it. So you can not inject 2 events back to back faster than that.
You could either write your own input command which would accept multiple sets of coordinates in one take thus eliminating the need to run the command multiple times. Or you could use series of sendevent commands for emulating your gesture instead.
This question already has answers here:
ADB Command to set volume?
(6 answers)
Closed 4 years ago.
I am trying to change the volume on my android device using
service call audio 9 i32 50
to set the volume to 50%. Additionally, when I do:
service call audio 16
I was able to see that the hex value is 32. However, I don't see any changes on the device. The volume has not been changed.
On the other side, when I change the volume on the device by pushing the volume-up button, I don't read any changes when I do service call audio 16.
I want to change the volume by setting a direct value without using input keyevent KEY_VOLUME_UP (or DOWN).
Any help?
Thanks!
Thank you for the quick response, but I found the solution, which is by using
"adb shell service call audio 7 i32 3 i32 0 i32 1"
Where 7 is the seventh function in "interface IAudioService" list: setStreamVolume(int streamType, int index, int flags, String callingPackage), 3 is speaker, 0 is the volume level and 1 is a flag.
The second number (3) represents the following options:
1: phone
3: speaker
4: alarm
6: Bluetooth
Note:
I was running as root when I tried the solution posted in my question but it didn't work.
For speaker - to change media volume, to set it to 0
adb shell service call audio 3 i32 3 i32 0 i32
I want to change the timezone using adb shell command.
I went through some posts which allow changing it in linux, but they are not valid for android.
For the list of tzdata values I go to http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
To set the timezone use setprop persist.sys.timezone <TZ> command:
setprop persist.sys.timezone "America/Chicago"
adb shell service call alarm 3 s16 America/Phoenix, which will be effective immediately.
"setprop with persist.sys.timezone" only works after reboot.
adb shell service call alarm 4 s16 America/Chicago
4 - stands for the fourth function in alarm service implementation.
s16 - stands for string argument type.
https://android.stackexchange.com/questions/34625/where-to-find-description-of-all-system-bin-service-calls
In my (very) limited experience I have been able to edit the /system/build.prop file. I change the line in there that says persist.sys.timezone=America/Sao_Pao or some such drival to persist.sys.timezone=America/Chicago for my timezone CDT. I also changed the lines persist.sys.language=bt and persist.sys.country=AR to persist.sys.language=en and persist.sys.country=US respectively.
There are a few other things you can tweak in the file that will persist after a system restore. You might want to make sure that the build.prop file in a flash image or directory has the correct lines in it.
The /system/property directory seems to hold several text files with a single value. These seem to show up after using setprop but the OS doesn't seem to reflect the changes.
Editing these files usually does require root access either with a term program or the ADB.exe shell. (ADB = Android Device Bridge available in the Android SDK) I found ADB.exe while looking through the firmware downloads at JXD.HK for the S18 MiniPad. In the files.rar dl there is also the SuperUser.apk and a rooted version of busybox and su.
Best of Luck !!!
Please see this https://gist.github.com/jpkrause/6b7e576894a800d451bf for answer to your question.
So in your case it would be:
adb shell setprop persist.sys.timezone America/Chicago
This works with ADB
Get current global time zone:
adb shell settings get global time_zone
Set a time zone:
adb shell settings put global time_zone Europe/Madrid
Time zones list:
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
I changed 2 files to change my timezone.
the one that i don't entire know if it's necessary, but it keeps things in sync:
/etc/timezone
the more one you for sure need to change:
/etc/localtime
from http://www.cyberciti.biz/faq/linux-unix-set-tz-environment-variable/ you can determine the name of the timezone you want with tzselect.
I took inspiration from http://www.cyberciti.biz/faq/howto-set-date-and-time-timezone-in-freebsd/
and copied my timezone file from /usr/share/zoneinfo/ to /etc/localtime.
/etc/timezone is a text file with the name of the timezone. so i just updated it to match the value provided by tzselect.