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
Related
I'm using a Samsung phone with Android 10
I found this adb command online
adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "${phone}" s16 "null" s16 "'${text}'" s16 "null" s16 "null"
This works, it sends the SMS if i respect the character limit. However, the SMS does not show up in the phone's messages app
I can't find documentation about all those flags and what they mean. Please help me and tell me how I can make it show in the messages app. If this is not possible with adb, is there any other way?
I was able to achieve this by providing another argument at the end
i32 1
this article helped me
Based on this documentation it seems i needed to provide the persistMessageForNonDefaultSmsApp boolean
Not sure if this was the way to go, I'm not an android dev, but it works :/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I would like to change the output device of my Android 9 LineageOS device because I'm constantly facing the problem that audio is being played through the phone's speakers instead of my Bluetooth headphones. I don't know why Android sometimes decides not to use the connected audio device, but I assume it is a bug as it only happens sometimes.
As a workaround I would like to use the terminal in order to fix this whenever it happens.
My idea: Find out which service manages audio output, figure out which method I have to call and what the parameters need to be and then use the service utility from a shell script or terminal (which has root access).
I think my service is simply called "audio" (IAudioService).
In the source code, the 35th method is "setBluetoothScoOn" which sounds like it could be what I'm looking for. It accepts one parameter (a boolean which I want to be true). So I ran this in my root terminal:
service call audio 35 i32 1
#audio: service name
#35: setBluetoothScoOn is the 35th method in in the IAudioServicesource code
#i32: data type to be used for the first parameter (boolean)
#1: means true in this context
The source code file I was talking about:
https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r1/media/java/android/media/IAudioService.aidl
Unfortunately nothing happens when I run my command. It just returns:
Result: Parcel(00000000 '....')
Any ideas what I'm doing wrong?
Edit:
When I am successfully connected having music being played (using VLC) through my Bluetooth headphones and run service call audio 38, I get the following response:
Result: Parcel(00000000 00000001 '........')
When I then run service call audio 37 i32 0 my phone immediately plays the audio through the phone's speakers instead of the Bluetooth headphones.
Then when I run service call audio 38 I get the following response:
Result: Parcel(00000000 00000000 '........')
As soon as I play the next song, audio plays through the Bluetooth headphones again though. And service call audio 38 returns this again:
Result: Parcel(00000000 00000001 '........')
This makes me wonder if 37 responds to setBluetoothScoOn and 38 to isBluetoothScoOn.
In a different situation, when I run service call audio 38 while I have my standard issues of having the Bluetooth headset connected and music plays through the speakers and refuses to play through the Bluetooth headphones, I still always get:
Result: Parcel(00000000 00000001 '........')
Until I run service call audio 37 i32 0, then it temporarily returns:
Result: Parcel(00000000 00000000 '........')
again until I play the next song, but at no point is audio playing through the Bluetooth headphones.
So essentially
service call audio 37 i32 1 only causes service call audio 38 to temporarily return:
Result: Parcel(00000000 00000001 '........')
Just like service call audio 37 i32 0 causes it to return:
Result: Parcel(00000000 00000000 '........')
But while plaxing music through Blurtooth, service call audio 37 i32 0 also temporarily plays audio through the speakers until I play the next song.
I'm making a shell script to control txt msg from my s5 phone and I've tried 2 different ways:
1)
am start -a android.intent.action.SENDTO -d sms:$1 --es sms_body "$2" --ez exit_on_sent true
sleep 1
input keyevent 22
sleep 1
input keyevent 66
2)
using DDMS to get the coordinates of the send button, x, y
service call isms 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText".
input tap x y
My goal is to generalize this for different phones that I want to test, and 1) doesn't send the message at all. It just loads sms app with the send to number and message body while not actually pressing the send buttong.
2) Works, but is specific to my phone. Some phones have the keyboard showing to coordinates are different, and additionally, most of my phones have different resolutions.
Is there a better way to automate the sending process? Like a keyevent code, or even an action to perform the last and most important step (for what I need this script for) of actually sending the message?
So the SENDTO syntax is for the default Android API's packages. It turns out my verizon messaging app behaves differently. All I had to do was reset my default text messenger to the android messenger and not the verizon one.
Example: Samsung S5 Verizon default: Messages and NOT Message+(verizon)
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
Do you know the command "service call isms" with adb shell on Android?
Here is the complete command I use : service call isms 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText".
There are some parameter but I don't know what it means (5, s16, i32, 0). Is there somewhere a manual ?
The most important for me is to get an error when the sms doesn't send successfully (about 10% of the sms aren't send) => this question asked already but there isn't answer (https://stackoverflow.com/questions/17395546/get-status-sms-from-isms-service-using-shell-adb-android-sdk).
I don't wanna use the commands
(adb shell am start -a android.intent.action.SENDTO -d sms:CCXXXXXXXXXX --es sms_body "SMS BODY GOES HERE" --ez exit_on_sent true
adb shell input keyevent 22
adb shell input keyevent 66)
because it uses the graphical interface.
Could you help me? (I'm sorry, I can't speak English. So, I hope you understand my request)
Thanks a lot
In every "service call" command, you need to enter:
the service you want to call, in this case it is "isms";
the "function" you want to call, in this case it is "5" (more about that later);
the function parameters.
There's two types of possible parameters: Strings and Integers. Before entering an Integer parameter you need to specify its type using i32.
Same thing for a String parameter, but instead you need to write s16.
Most of the "service call" commands have no documentation, or very little.
For the ISms you can look here: http://www.androidjavadoc.com/1.0_r1_src/constant-values.html
to get a list of the possible functions and their number code. Hit ctrl-f and enter ISms for quick access.
The "5" function for the ISms service is the sendMultipartText function from the ISms interface of the Android API. Here is the doc about this function. And here is the implementation class from the API.
So, service call isms 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText", equals:
Call the sendMultipartText function from the ISms service with the
String parameter "PhoneNumber", the Integer parameter 0, the Integer
parameter 0 and the String parameter "BodyText".
To answer your question, I am pretty sure there's no way to know if the sms are being sent or not from the command line... But maybe if you dig a little deeper than I did in the API you'll find a way.