I have requirement like i need to take a UI dump of each window that appears on my android app to verify resource-id given is unique.
basically i want do what this command "adb shell uiautomator dump" does inside the android app.
#CommonsWare may be correct. But I tested the code below on two non-rooted devices and I was able to get an output. (Nexus 6P and Samsung S5)
#Gokul
I found the key was to NOT specify "adb shell" beforehand as it must be in the path already and I get a permission error if I attempt to use it.
Doing something like this:
String command = "service list";
Process process = Runtime.getRuntime().exec(command);
Worked for me running in a unit test on two real non-rooted devices.
This produces the same results as running the command: "adb shell service list" from the command prompt.
Related
I'm trying to set the profile owner for one of my application using command on my Android 10 device:
adb shell dpm set-profile-owner com.example.blockcamera/.BlockCameraDeviceAdminReceiver
When I press Enter nothing happens - the command will be stuck with a cursor flashing on new line. I have to Ctrl+C to kill it.
The command works fine on Android Emulator and the app works as expected afterwords.
I am using android:testOnly flag in AndroidManifest.xml
Things tried:
Used --user current option but no luck
Also tried set-device-owner command but same result, the command gets stuck.
I reset the device and it worked later.
I am trying to set-up a command in Android studio that would allow me to see the current active devices like in this tutorial (1:39:41):
I have opened the environment settings and created the variable adb devices like it was explained in the tutorial
However, when I run it in Android Studio Terminal, the command is not recognised:
What did I do wrong?
The problem is with your naming. Try remove the white space and it will work.
Cause you type adb with argument devices.
Try change your variable to adb
then type
$ adb devices
and it will work
Maybe I'm just missing it but is there a way to view WHAT is running in the background on-device in android studio?
I'm getting a battery usage alert on my phone (galaxy s8 - OS v8.0), indicating my app is doing something in the background and I'd like to see what it is.
Thank you
Yea, via the terminal function. This is one of options at the bottom of the Android studio.
You need to run ADB to connect to the device. Once connected you can use Unix command lines to see the processes running.
From google dev : https://developer.android.com/studio/command-line/adb
Also, the command I use to connect an emulator to run unix commands is:
adb -s <DEVICE> shell
Normally the ADB is stored :
USER\AppData\Local\Android\Sdk\platform-tools
and then once connected you can use the following to see the running processes :
https://www.howtogeek.com/107217/how-to-manage-processes-from-the-linux-terminal-10-commands-you-need-to-know/
Hope this helps.
I'm working on script which suppose run CTS Tests on multiple devices.
unfortunately, while i check the serial number of my android devices I see that part of them contains identical serial number.
now, I read about an option to run adb devices -l to get usb entering of my devices, in order to I could run command on specific usb:
$ adb devices -l
List of devices attached
0123456789ABCDEF device usb:2-1.8
0123456789ABCDEF device usb:2-1.7
now, we can run this command on specific usb instead specific serial number as before:
$ adb -s usb:26200000 install xxx.apk
I want to do similar thing while I run CTS on specific android device:
$ ./cts-tradefed run cts -s usb:2-1.8 -p android.permission2
The problem is that it looks like the command not working. there isn't any response when I try this.
please, anybody can tell me if there is another way to run cts on specific device while there are two identical serial numbers?
There is another way of forcing adb to use a specific device besides -s parameter. You can assign your device id to the ANDROID_SERIAL environment variable. That works great for 3rd party scripts which do not support specifying the required id otherwise.
You can select between multiple devices you use the command list devices to get the serial of the devices:
l d
Example
cts-tf > l d
Serial State Allocation Product Variant Build Battery
10.1.1.113:5555 ONLINE Allocated product variant 2018.02.2 100
and then run cts with --serial parameter
run cts --serial <id>
where <id> is the first column in the result from l d command
Even if the parameter's name is serial in fact the value you give to it is the device id(as given by the command l d or list devices) and not the actual serial of the device.
What is the default built in shell in Android phones and can I run runtime.exec Java method without installing a shell ?
You can call runtime.exec(String) in Android but it won't get you very far, because the runtime doesn't really offer commands to consume. However, if you've got a rooted phone with busybox and su installed, it is possible to call those embedded commands. It's even possible to create a superuser session by executing the su binary and consuming the streams of it.