How can I create new contact using adb?
I'm using the following command:
adb shell "am start -a android.intent.action.INSERT -t vnd.android.cursor.dir/contact -e name 'Bo Lawson' -e phone 123456789"
But now, Should I need to click on Save, So how can I do it fully automatic using adb?
Try adb shell input keyevent 3 This will take your phone back to the home screen which will automatically save the contact.
You can use adb to simulate touch events by using the following command
adb shell input tap x y
Related
We are trying to dial the code
"*%2306%23" = "*#06#"
through the adb command to fetch the information about the IMEI
adb -s "DEVICE SERIAL" shell am start -a android.intent.action.DIAL -d tel:*%2306%23
The connected device shows the code on the screen but doesn't auto-dial. But, when we try to dial manually it's working fine.
The device is connected and the developer option is enabled.
Any help would be appreciated.
The intent that you are sending only opens the dialer app and enters the number, it does not dial. In order to dial you have to press the call button - adb shell input keyevent KEYCODE_CALL, but...
you are not dialing a regular number, you want to enter some code, so you have to open the dialer and enter the code symbol by symbol:
adb shell am start -a android.intent.action.DIAL
adb shell input keyevent KEYCODE_STAR
adb shell input keyevent KEYCODE_POUND
adb shell input keyevent KEYCODE_0
adb shell input keyevent KEYCODE_6
adb shell input keyevent KEYCODE_POUND
When I need to see my doctor I have to:
Call to 666666666
Wait 5 seconds
Press 1
Wait 5 seconds
Press 20301990
Wait 5 secondos
Press 1
So I want to automatizate all this steps
I know that I can fire the call doing:
adb shell am start -a android.intent.action.CALL -d tel:666666666
and I can simulate a input by:
sleep 5
adb shell input text "1"
sleep 5
adb shell input text "20*30*1990"
sleep 5
adb shell input text "1"
but It can't work if I don't open de dial pad after adb shell am start -a android.intent.action.CALL -d tel:666666666 and before adb shell input text "1"
So my question is: How can I open the dial pad during a call using adb?
You can find the coordinates of the dial's pad button and then simulate a press by sending input tap x y.
If your automation will be used on multiple devices from different types, I would advise you to write a simple python script that uses uiautomator to do that task.
I have an android phone on which I want to programatically toggle airplane mode.
I've been unable to root this device, which has prevented any apps I'm running from having permission to edit these settings, so am using adb to open the settings menu and toggle the switch there.
Executing the following adb shell commands will work in some cases:
//Get airplane mode settings menu
adb -s ${device} shell am start -a android.settings.AIRPLANE_MODE_SETTINGS
//Hit enter (as many times as required)
adb -s ${device} shell input keyevent KEYCODE_ENTER
//Check the state of airplane mode to determine when successful
adb -s ${device} shell settings get global airplane_mode_on
However, this only work if the menu containing the airplane mode switch is the first menu option listed on the settings page, since "android.settings.AIRPLANE_MODE_SETTINGS" will only navigate to the menu where the setting is found. It will not perform any focussing on the setting itself, so the following command to hit enter will press the wrong setting.
If using this approach, is there a way to identify/focus only the airplane toggle switch, or otherwise check which menu item is in focus so the items can be iterated until the correct one is found?
Additionally, it would be great if there was a way to execute these adb commands without requiring the phone to be plugged into a PC - i.e. can the adb client be run on the phone itself (and then trick itself into thinking it is a connected device).
And finally - the end goal here is simply to toggle airplane mode programatically on demand (ultimately the request will be triggered by a node.js process running in termux app). If there is a better way to achieve this without using adb that doesn't require root permissions, this would also work.
Here are the ADB commands to turn on and turn of airplane mode:
Turn on:
adb shell settings put global airplane_mode_on 1
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
Turn off:
adb shell settings put global airplane_mode_on 0
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
I suspect this is an incredibly niche requirement, but if anyone is interested in how to toggle airplane mode on a non-rooted android phone using adb commands, where the UI airplane mode toggle button is not the first item in the settings activity.... read below!
As previously mentioned, load the screen containing the airplane mode button:
adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS
Now to check the current state of the UI:
adb shell uiautomator dump
adb pull /sdcard/window_dump.xml
STDOUT of the first command above can be checked to determine exactly where the uiautomator dump is sent by default.
To navigate the settings menu, use the DPAD UP/DOWN keyevents:
adb shell input keyevent KEYCODE_DPAD_DOWN
adb shell input keyevent KEYCODE_DPAD_UP
Depending on the device, I've found that using the above options either results in nodes being selected or focused. The output of the UI dump can be parsed, and in the DOM search for either "node[selected=true]" or "node[focused=true]" depending on which the device uses. I'm eventually checking to see when node.attr('text').toUpperCase.contains('PLANE MODE') to check when the airplane mode setting has been reached, and then finally executing:
adb shell input keyevent KEYCODE_ENTER
to activate the switch.
For now this covers the devices I've tried it on, but performance is not great if there is a lot of scrolling in the menu to do. I'd be interested to know if there's a way to hold uiautomator dump output in memory on the device and parse the XML there to avoid unnecessary I/O of outputting to a file, pulling to a local drive and reading it back into memory there.
Create bat file:
adb -s 3e31d8d97d95 shell am start -a android.settings.AIRPLANE_MODE_SETTINGS ; while [ 0 -le 5 ]; do input keyevent 23; sleep 0.1;input keyevent 23;sleep 13; echo 'done'; done;
Make sure the "stay awake" is ON in debug menu.
Also make sure this is more "gray" - focues:
Run the script.
if [[ "$(adb shell dumpsys wifi | grep mAirplaneModeOn)" == "mAirplaneModeOn false" ]]; then
adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS
&& input keyevent 19
&& input keyevent 23
&& input keyevent 4
fi
Did anyone tried Android multiple display feature which is new in Android O
Following steps which is not working for me
1.connect hdmi cable to mobile(not sure can use USB as well)
2.make device in root and give following command (expect app is installed)
and not seen that app is launching on secondary(Multiple display feature
) it's just reflecting mobile display as it is because connected hdmi cable
adb shell am start com.Chrome.Canary --display 1
Please suggest any other way or any command to make it work?
Android in general do mirroring when two displays are connected. Right now google has not enabled support for touch and display mapping on the two displays. But if you want to launch any activity on any of the two displays then the command adb shell am start "your_activity" --display display_id will launch your activity on that particular display id. If the above command doesn't launch your activity then you can use adb shell am stack start display_id "your activity". This will also work. But regarding touch, it will be mapped to the primary display (display id 0). As per google you can enable the mapping of touch in EventHub.cpp of Android source code but till now I haven't found it useful. Hope my answer helps you.
Ran using below procedure passed with dell monitor:
ADB shell can be used to call Activity Manager(am) for starting any system actions (or an activity).
The syntax:
adb shell am start [-n (component)] [-a (action)] [-t (mime type)] [-d (data_URL)]
examples:
1. For starting ‘Settings app’:
adb shell am start -n com.android.settings/.Settings
In the above-mentioned command, we set component(-n) to be settings in a specific format.
For starting ‘Gallery app’:
adb shell am start -t image/* -a android.intent.action.VIEW
In the above-mentioned command, we are setting action(-a) for opening the default app for gallery with mime type(-t) to be image/*
In general, for external display the ‘display_id’ starts from ‘1’ in an increasing order, final command to do multi display operation is
adb shell am start -n com.android.settings/.Settings --display 1
The above command will display ‘Settings’ app only in external display with display_id = 1. The primary display will be in the same mode as before executing the command.
Can some one tell me how i can initiate & pickup a video call using adb? I want to automate some Video Telephony Testing and want to do this using adb_scripts. Is it possible at all?
I can see the following link in stackoverflow to initiate a voice only call using adb. I just cannot correlate the same to initiate video call.
How to make a call via pc by ADB command on android?
Thanks in advance.
\\ To Initiate the Video call
adb shell am start -a android.intent.action.CALL -d tel:xxx-xxx-xxxx --ei android.telecom.extra.START_CALL_WITH_VIDEO_STATE 3**
\\ To auto answer on far end
adb shell setprop persist.sys.tel.autoanswer.ms 2000
Have you tried this for setting up a call:
adb shell am start -a android.intent.action.CALL -d tel:+1-xxx-xxx-xxxx
This ends a call:
adb shell input keyevent 6
I have not tried this but it might answer a call:
adb shell input keyevent 5