Using ADB command know the name of application focussed using adb [duplicate] - android

This question already has answers here:
ADB - Android - Getting the name of the current activity
(13 answers)
Closed 4 years ago.
I am using the
adb shell input keyevent KEYCODE_DPAD_LEFT
to focus on an application, now i want to know the name of the application on which this has focussed using adb shell command.
NOTE: not exactly the name of application, it can focus on anything. SO i want to get the Text on which it focusses.

Ok. To do it, you need to use grep terminal application on your phone (the easiest way with rooted phone with busybox package). Let do the same steps as below:
C:\Users\Hasan>adb shell input keyevent KEYCODE_DPAD_LEFT
C:\Users\Hasan>adb shell
shell#android:/ $ su
su
root#android:/ # dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
mCurrentFocus=Window{42079c60 com.jrummy.liberty.toolboxpro/com.jrummy.apps.rom.toolbox.RomToolboxActivity paused=false}
mFocusedApp=AppWindowToken{4283d918 token=Token{426709a8 ActivityRecord{41e37c60 com.jrummy.liberty.toolboxpro/com.jrummy.apps.rom.toolbox.RomToolboxActivity}}}
root#android:/ #
Now you'll see which activity has focus :)

You can use:
adb shell uiautomator dump /dev/tty
You will get an XML describing the current screen, one of the many <node>-elements will have an attribute focused="true". It may also have a text-attribute and a lot more UI-informations.

Related

Unable To get Activity name from adb command Android 10

I'm trying to get activity name for current focused app on the device by running this command:
adb shell "dumpsys window windows | grep -E 'mCurrentFocusApp|mFocusedApp'"
It works on older phone with Android 6.0 but on Pixel XL running Android 10 its returns nothing.
If I run only dumpsys window windows it returns bunch of unfiltered info which is not very efficient for me.
adb shell dumpsys activity a . | grep -E 'mResumedActivity' | cut -d ' ' -f 8
John answer is great but u can use:
adb shell dumpsys window windows | grep mActivityRecord
in that case u get list of all current run app in memory
if u kill all app and run the one u want u get 2 records
# launcher
mActivityRecord=ActivityRecord{99197dc u0 com.sec.android.app.launcher/.activities.LauncherActivity t3161}
# active app
mActivityRecord=ActivityRecord{6dec4d5 u0 com.google.android.googlequicksearchbox/com.google.android.apps.gsa.monet.MonetActivity t3711}
adb shell dumpsys activity activities | grep "mFocused"
It worked on android 10 & 11.

why i can't get adb shell top works?

I'm testing an android app by my PC. I try to catch the CPU usage of it.
if I use
adb shell top -m 10 |tee aa.txt
it works fine.
but if i modify it like this
adb shell top -m 10 |grep myAPPname|tee aa.txt
it can not. Why and how to make it work again?
try the command below:
while true; do
adb shell top -m 10 -n 1 | grep kso >> aa
done
-n means only show the current status instead of updating frequently.
However, I suggest you use Android Profiler which is a built-in function in Android Studio to achieve your monitoring work.

ADB logcat exit on tag [duplicate]

This question already has an answer here:
Send data back to the script which started the activity via adb shell am start
(1 answer)
Closed 4 years ago.
Im trying to filter android logcat at real time and execute some command or exit from logcat when specific tag occured. I tried the following:
adb shell "logcat | grep 'sometag' && echo 'Tag occured'"
adb shell logcat -m --regex='sometag'
In second command -m does not work at all, but is listed in logcat documentation.
Any ideas how can i do this?
Answer (maybe temporary because infinite loop is not a best idea):
Because i'm scripting in PowerShell i found that solution:
While(1) {
$log = & $abdPath shell "logcat -d | grep 'onPause'"
if($log) {
break;
}
}
Thanks for down voting without any reason :)

adb screencap creates corrupted file [duplicate]

This question already has answers here:
Read binary stdout data like screencap data from adb shell?
(19 answers)
Closed 5 years ago.
I'm trying to take a screenshot on my Android device with adb. I'm able to connect to my device and execute the commands, but the result is a corrupted file.
Im on a Ubuntu 14.04 system.
My device is a Nexus 6 with Android 6.0 Beta on it.
I do the following:
adb shell screencap -p | sed 's/\r$//' > screenshot.png
I tried this as well:
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
I know it's also possible to use the pull method. But I prefer this one because it's faster.
hey this is how i screencap our app, though i am using win7
adb shell screencap /sdcard/screen.png
also, i don't know what's that weird tags. when you use android's native screen capture command, android saves it on Pictures/Screenshot if i remember it right. i am using a Samsung Galaxy Tab 3.

Get Android OS version of device connected via ADB [duplicate]

This question already has answers here:
Android ADB commands to get the device properties
(4 answers)
Closed 7 years ago.
Can one use adb or adb shell commands to get attached emulator/device OS info, i.e. API version?
To get Android version you can use:
adb shell getprop ro.build.version.release
to get API level:
adb shell getprop ro.build.version.sdk
You can see all available properties with this command:
adb shell getprop
I know , you already got the correct solution , & here is my solution only for additional information.
You will get every details by cat ing the /system/build.prop file like
adb shell cat /system/build.prop
Here is collection of adb commands
For all properties:
adb shell getprop

Categories

Resources