Running the Android UiAutomator on real device - android

I'm able to run my Uiautomator test cases on emulator easily, on both API 16 and 17.
If I run same test case on real device it get stuck in the 1st line only.
I'm not sure with the steps to run on the real device
UiScrollable has some issue, I guess. When I write getUiDevice().pressHome(); it works, but after that nothing works. I'm using the same code written in the Android developer site for Uiautomator (http://developer.android.com/tools/testing/testing_ui.html)

Use uiautomatorviewer to dump the UI hierarchy of your device's home screen. As user2575698 says, it is likely that there is no UiObject with description "Apps".
Also you have to keep in mind that the sample from the android developer site requires the device to have the screen on and that no screen lock is present. Making sure that the screen is on can be done in the following way:
UiDevice device = getUiDevice();
if (!device.isScreenOn()) {
device.wakeUp();
}
device.pressHome();
Screen lock can be disabled in Settings.

Maybe it cannot find the object with description "Apps" on your real devices,you need to give logs for detail things

use "adb shell uiautomator dump " command to get window dump. Then to to sd card and look for dump xml. There look for content-desc attribute of node and code according to that value. content-desc can be different on different device as for application in samsung it is "Apps" but in HTC one it is "All apps".

Related

Some Samsung phones with Android 6 or higher don't have android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS

My app needs to allow users to disable doze mode for my app, so for that the app needs to open android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS but I get android.content.ActivityNotFoundException when trying to open that intent on some Samsung phones like the Galaxy A5.
Is there an equivalent on those phones? What about other phones?
Thanks.
Edit: I just want to be clear, I'm trying to find what the actual setting screen is on Samsung Phones like the A5, not just how to open settings. I need to direct the users to the right location.
Edit: To clarify further, we have no found the setting on that Samsung phone to make isIgnoringBatteryOptimizations() return true. That is my main question, what setting needs to change on that phone for that to become true.
The Samsung Galaxy A5 ran on three OSs:
Android 6.0.1, Android 7.0, Android 8.0.0 (GFX Bench)
The android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS activity was added in API 23. It was not removed afterwards. For some reason, this bug was never addressed by Samsung. The only solution is to bring the user to the system settings screen. See the following solution:
https://github.com/kontalk/androidclient/commit/be78119687940545d3613ae0d4280f4068125f6a
EDIT
After misunderstanding the question and with the clarification of the OP, I've added a potential solution to address which power setting needs to be accessed.
If you haven't already, make sure you are using android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. Be sure that you add REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in your manifest prior to using this activity.
Activity Action: Ask the user to allow an app to ignore battery optimizations (that is, put them on the whitelist of apps shown by ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS). For an app to use this, it also must hold the Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission.
This should bring the user to the exact option necessary.
If you have one of these phones (maybe virtual from some online services) you can run the adb command to find the running activities, this way you can check the intent and maybe you are allowed to call it:
adb shell dumpsys activity activities

getting terminal output while using android studio

While coding, sometimes we'd like to put some simple print statements at some location just to see some specific behaviour, but, when running android studio, our app is basically running on a physical cellphone(in this case, just considering the cellphone and not an emulator), but, how do I make the print statements print to my computer's terminal?(Currently using ubuntu 16)
Log calls (e.g., Log.d()) are recorded by Logcat. Those messages are visible directly in Android Studio in the Logcat tool window. If you really want to view Logcat in a terminal window, use adb logcat.
Piggy-backing off what #CommonsWare pointed out, you can also use the Run window to see less of the system logs and information more specific to your actual run of the app. This was helpful for me in the beginning but sometimes you need the verbosity of the Logcat window. If you end up using the Logcat window, there should be a search bar at the top of the window that you can use to filter out specific messages.
For example, if you call Log.i(tag, message), you can search for tag in the Logcat window and only those messages will be shown! Hope it helps narrow your search.

Google Glass - screen won't appear after update

Now that XE16 is available, I decided to update my Glass with the new boot.img. Everything looked like it succeeded, but when I restarted the Glass, the main screen doesn't appear. When I try to use adb commands, it says my device is unauthorized and that I should check the appropriate dialog.
I'd love to check the dialog, but as I said, the screen won't appear.
Is there anything I can do?
It looks like a mismatched boot.img? Try either building the kernel or extracting it from the factory system image (assuming you tested that image).
As for building, the instructions reference glass-omap-xrr02 but the latest accessible one is glass-omap-xrv34 (for XE17). update: glass-omap-xrv60b XE17.2

is it possible to invoke ICS screen shot function from adb?

I would need to be able to take screen dumps for testing, and with ICS there is now a screen shot function, that can be invoked by pressing (and holding) volume down and power button.
Is there any way to script this function through adb? (As I understand it there's no public java API for it). I have tried to use KeyEvent from java to emulate power and volume button, and I have tried to use adb keyevent and adb sendevent without success. I suspect that the power button also generate some low level calls that are not generated with the above methods.
So do anyone know if it is possible to call the function from adb?
If this is not possible, do someone know where in the source code this screen shot function exist? Maybe I can figure something out by reading it.
update
source code for capture the screen is in "frameworks/base/services/surfaceflinger/services/surfaceflinger/SurfaceFlinger.cpp" in a function called screenCapture. I do not know if it is possible to call it from jni, but I will try, because it would be great if I could take a screen shot through java.
Otherwise, #edthethird had a solution through android.amberfog.com/?p=168 that will make it possible to take a screenshot with the commandline.
Thank you for the help everyone!
In the form of adb commands, the following works on ICS devices:
adb shell /system/bin/screencap -p /sdcard/img.png
adb pull /sdcard/img.png img.png
See: http://a-more-common-hades.blogspot.com/2012/01/screenshot-command.html
Well this has nothing to do with ICS, but in eclipse, look at a Devices tab. There is a tiny little camera icon on the far right. (From right to left, it is "box", "line", "upside down triangle", and "camera". Click on this camera to take a screen shot of the currently selected device.
This works on any version of Android, not only ICS.
See this question:
Screenshot of the Nexus One from adb?
Basically you can pull the framebuffer using adb and convert it into a usable image yourself, or you can just use the command line utility provided by Google. Looking round I think you may need to tweak that utility a little to get it to work on newer versions of Android.
As the other answer points out though, its probably less hassle to just do this from Eclipse, unless you're trying to automate testing.
After looking into the source code, there is a library that does exactly what I want.
frameworks\base\cmds\screencap\screencap.cpp
The program can be executed on android by /system/bin/screencap .
So it is possible to execute in Java on android by Runtime.getRuntime().exec();
A drawback is that you need a special certificate for taking screenshots.

what is the easiest way to take screen spots of an android app?

I have recently gotten a new android phone and it does not have root intill the 30 day warranty is up.my older android has root access but it is my sisters now.i use to use drocap
So what im asking is there a way were I can take a screen shot of my app in the emulater.i know on a mac (thats what I use) you can take screen spots with command shift 4. But is there something for the emulater in eclipse that I can use to take screen shots?
Android DDMS allow screen capture from an emulator.
Search for screen capture in the DDMS tool documentation .

Categories

Resources