Adb - Android - Getting the Name of the Current Activity

ADB - Android - Getting the name of the current activity

You can use this command,

adb shell dumpsys activity

You can find current activity name in activity stack.

Output :-

 Sticky broadcasts:
* Sticky action android.intent.action.BATTERY_CHANGED:
Intent: act=android.intent.action.BATTERY_CHANGED flg=0x60000000
Bundle[{icon-small=17302169, present=true, scale=100, level=50, technology=Li-ion, status=2, voltage=0, plugged=1, health=2, temperature=0}]
* Sticky action android.net.thrott.THROTTLE_ACTION:
Intent: act=android.net.thrott.THROTTLE_ACTION
Bundle[{level=-1}]
* Sticky action android.intent.action.NETWORK_SET_TIMEZONE:
Intent: act=android.intent.action.NETWORK_SET_TIMEZONE flg=0x20000000
Bundle[mParcelledData.dataSize=68]
* Sticky action android.provider.Telephony.SPN_STRINGS_UPDATED:
Intent: act=android.provider.Telephony.SPN_STRINGS_UPDATED flg=0x20000000
Bundle[mParcelledData.dataSize=156]
* Sticky action android.net.thrott.POLL_ACTION:
Intent: act=android.net.thrott.POLL_ACTION
Bundle[{cycleRead=0, cycleStart=1349893800000, cycleEnd=1352572200000, cycleWrite=0}]
* Sticky action android.intent.action.SIM_STATE_CHANGED:
Intent: act=android.intent.action.SIM_STATE_CHANGED flg=0x20000000
Bundle[mParcelledData.dataSize=116]
* Sticky action android.intent.action.SIG_STR:
Intent: act=android.intent.action.SIG_STR flg=0x20000000
Bundle[{EvdoSnr=-1, CdmaDbm=-1, GsmBitErrorRate=-1, CdmaEcio=-1, EvdoDbm=-1, GsmSignalStrength=7, EvdoEcio=-1, isGsm=true}]
* Sticky action android.intent.action.SERVICE_STATE:
Intent: act=android.intent.action.SERVICE_STATE flg=0x20000000
Bundle[{cdmaRoamingIndicator=0, operator-numeric=310260, networkId=0, state=0, emergencyOnly=false, operator-alpha-short=Android, radioTechnology=3, manual=false, cssIndicator=false, operator-alpha-long=Android, systemId=0, roaming=false, cdmaDefaultRoamingIndicator=0}]
* Sticky action android.net.conn.CONNECTIVITY_CHANGE:
Intent: act=android.net.conn.CONNECTIVITY_CHANGE flg=0x30000000
Bundle[{networkInfo=NetworkInfo: type: mobile[UMTS], state: CONNECTED/CONNECTED, reason: simLoaded, extra: internet, roaming: false, failover: false, isAvailable: true, reason=simLoaded, extraInfo=internet}]
* Sticky action android.intent.action.NETWORK_SET_TIME:
Intent: act=android.intent.action.NETWORK_SET_TIME flg=0x20000000
Bundle[mParcelledData.dataSize=36]
* Sticky action android.media.RINGER_MODE_CHANGED:
Intent: act=android.media.RINGER_MODE_CHANGED flg=0x70000000
Bundle[{android.media.EXTRA_RINGER_MODE=2}]
* Sticky action android.intent.action.ANY_DATA_STATE:
Intent: act=android.intent.action.ANY_DATA_STATE flg=0x20000000
Bundle[{state=CONNECTED, apnType=*, iface=/dev/omap_csmi_tty1, apn=internet, reason=simLoaded}]

Activity stack:
* TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
clearOnBackground=false numActivities=2 rootWasReset=false
affinity=org.chanakyastocktipps.com
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.chanakyastocktipps.com/.ui.SplashScreen}
realActivity=org.chanakyastocktipps.com/.ui.SplashScreen
lastActiveTime=15107753 (inactive for 4879s)
* Hist #2: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
packageName=org.chanakyastocktipps.com processName=org.chanakyastocktipps.com
launchedFromUid=10046 app=ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
Intent { cmp=org.chanakyastocktipps.com/.ui.Profile }
frontOfTask=false task=TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
taskAffinity=org.chanakyastocktipps.com
realActivity=org.chanakyastocktipps.com/.ui.Profile
base=/data/app/org.chanakyastocktipps.com-1.apk/data/app/org.chanakyastocktipps.com-1.apk data=/data/data/org.chanakyastocktipps.com
labelRes=0x7f09000b icon=0x7f020065 theme=0x1030007
stateNotNeeded=false componentSpecified=true isHomeActivity=false
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
resultTo=HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen} resultWho=null resultCode=4
launchFailed=false haveState=false icicle=null
state=RESUMED stopped=false delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=0
fullscreen=true visible=true frozenBeforeDestroy=false thumbnailNeeded=false idle=true
waitingVisible=false nowVisible=true
* Hist #1: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
packageName=org.chanakyastocktipps.com processName=org.chanakyastocktipps.com
launchedFromUid=10046 app=ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
Intent { cmp=org.chanakyastocktipps.com/.ui.MainScreen }
frontOfTask=true task=TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
taskAffinity=org.chanakyastocktipps.com
realActivity=org.chanakyastocktipps.com/.ui.MainScreen
base=/data/app/org.chanakyastocktipps.com-1.apk/data/app/org.chanakyastocktipps.com-1.apk data=/data/data/org.chanakyastocktipps.com
labelRes=0x7f09000b icon=0x7f020065 theme=0x1030007
stateNotNeeded=false componentSpecified=true isHomeActivity=false
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
launchFailed=false haveState=true icicle=Bundle[mParcelledData.dataSize=1344]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=0
fullscreen=true visible=false frozenBeforeDestroy=false thumbnailNeeded=false idle=true
* TaskRecord{450615a0 #2 A com.android.launcher}
clearOnBackground=true numActivities=1 rootWasReset=false
affinity=com.android.launcher
intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher}
realActivity=com.android.launcher/com.android.launcher2.Launcher
lastActiveTime=12263090 (inactive for 7724s)
* Hist #0: HistoryRecord{4505d838 com.android.launcher/com.android.launcher2.Launcher}
packageName=com.android.launcher processName=com.android.launcher
launchedFromUid=0 app=ProcessRecord{45062558 129:com.android.launcher/10025}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher }
frontOfTask=true task=TaskRecord{450615a0 #2 A com.android.launcher}
taskAffinity=com.android.launcher
realActivity=com.android.launcher/com.android.launcher2.Launcher
base=/system/app/Launcher2.apk/system/app/Launcher2.apk data=/data/data/com.android.launcher
labelRes=0x7f0c0002 icon=0x7f020044 theme=0x7f0d0000
stateNotNeeded=true componentSpecified=false isHomeActivity=true
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
launchFailed=false haveState=true icicle=Bundle[mParcelledData.dataSize=3608]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=2
fullscreen=true visible=false frozenBeforeDestroy=false thumbnailNeeded=false idle=true

Running activities (most recent first):
TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
Run #2: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
Run #1: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
TaskRecord{450615a0 #2 A com.android.launcher}
Run #0: HistoryRecord{4505d838 com.android.launcher/com.android.launcher2.Launcher}

mPausingActivity: null
mResumedActivity: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
mFocusedActivity: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
mLastPausedActivity: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}

mCurTask: 22

Running processes (most recent first):
App #13: adj=vis /F 45052120 119:com.android.inputmethod.latin/10003 (service)
com.android.inputmethod.latin.LatinIME<=ProcessRecord{44ec2698 59:system/1000}
PERS #12: adj=sys /F 44ec2698 59:system/1000 (fixed)
App #11: adj=fore /F 44fa3450 1065:org.chanakyastocktipps.com/10046 (top-activity)
App #10: adj=bak /B 44e7c4c0 299:com.svox.pico/10028 (bg-empty)
App # 9: adj=bak+1/B 450f7ef0 288:com.dreamreminder.org:feather_system_receiver/10057 (bg-empty)
App # 8: adj=bak+2/B 4503cc38 201:com.android.defcontainer/10010 (bg-empty)
App # 7: adj=home /B 45062558 129:com.android.launcher/10025 (home)
App # 6: adj=bak+3/B 450244d8 276:android.process.media/10002 (bg-empty)
App # 5: adj=bak+4/B 44f2b9b8 263:com.android.quicksearchbox/10012 (bg-empty)
App # 4: adj=bak+5/B 450beec0 257:com.android.protips/10007 (bg-empty)
App # 3: adj=bak+6/B 44ff37b8 270:com.android.music/10022 (bg-empty)
PERS # 2: adj=core /F 45056818 124:com.android.phone/1001 (fixed)
App # 1: adj=bak+7/B 45080c38 238:com.dreamreminder.org/10057 (bg-empty)
App # 0: adj=empty/B 4507d030 229:com.android.email/10030 (bg-empty)

PID mappings:
PID #59: ProcessRecord{44ec2698 59:system/1000}
PID #119: ProcessRecord{45052120 119:com.android.inputmethod.latin/10003}
PID #124: ProcessRecord{45056818 124:com.android.phone/1001}
PID #129: ProcessRecord{45062558 129:com.android.launcher/10025}
PID #201: ProcessRecord{4503cc38 201:com.android.defcontainer/10010}
PID #229: ProcessRecord{4507d030 229:com.android.email/10030}
PID #238: ProcessRecord{45080c38 238:com.dreamreminder.org/10057}
PID #257: ProcessRecord{450beec0 257:com.android.protips/10007}
PID #263: ProcessRecord{44f2b9b8 263:com.android.quicksearchbox/10012}
PID #270: ProcessRecord{44ff37b8 270:com.android.music/10022}
PID #276: ProcessRecord{450244d8 276:android.process.media/10002}
PID #288: ProcessRecord{450f7ef0 288:com.dreamreminder.org:feather_system_receiver/10057}
PID #299: ProcessRecord{44e7c4c0 299:com.svox.pico/10028}
PID #1065: ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}

mHomeProcess: ProcessRecord{45062558 129:com.android.launcher/10025}
mConfiguration: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
mConfigWillChange: false
mSleeping=false mShuttingDown=false

Finding the name of the current activity from live layout inspector

Well, If you are using Android Studio Dolphin | 2021.3.1 or newer, there is no such straight way with layout inspector like the former version. However, you can find the related layout xxx.xml name,which could also help.
enter image description here

Touch any view, find Declared Attributes at the right panel,then shows the layout name, with which will find activty easily.

And also check this: Is there any way to track what fragment/s are visible right now?
Try the Profiler way.

adb command for listing all elements of current activity

Use this command

adb shell uiautomator dump

You will get a XML file here, an XML with the dump of current UI hierarchy

UI hierchary dumped to: /sdcard/window_dump.xml

You can then download it by accessing it from Android Studio device explorer.

Is there a way to get current activity's layout and views via adb?

Use adb shell uiautomator dump command:

Usage: uiautomator <subcommand> [options]

Available subcommands:

help: displays help message

runtest: executes UI automation tests
runtest <class spec> [options]
<class spec>: <JARS> < -c <CLASSES> | -e class <CLASSES> >
<JARS>: a list of jar files containing test classes and dependencies. If
the path is relative, it's assumed to be under /data/local/tmp. Use
absolute path if the file is elsewhere. Multiple files can be
specified, separated by space.
<CLASSES>: a list of test class names to run, separated by comma. To
a single method, use TestClass#testMethod format. The -e or -c option
may be repeated. This option is not required and if not provided then
all the tests in provided jars will be run automatically.
options:
--nohup: trap SIG_HUP, so test won't terminate even if parent process
is terminated, e.g. USB is disconnected.
-e debug [true|false]: wait for debugger to connect before starting.
-e runner [CLASS]: use specified test runner class instead. If
unspecified, framework default runner will be used.
-e <NAME> <VALUE>: other name-value pairs to be passed to test classes.
May be repeated.
-e outputFormat simple | -s: enabled less verbose JUnit style output.

dump: creates an XML dump of current UI hierarchy
dump [--verbose][file]
[--compressed]: dumps compressed layout information.
[file]: the location where the dumped XML should be stored, default is
/storage/emulated/legacy/window_dump.xml

events: prints out accessibility events until terminated

By default it dumps the views hierarchy to $EXTERNAL_STORAGE/window_dump.xml

adb shell uiautomator dump
UI hierchary dumped to: /sdcard/window_dump.xml

Usually you would want to pull that file to your PC for further processing which would be an extra step. But there is a neat trick which allows to combine dumping and pulling into a single command. Using /dev/tty as a dump destination would make a single command which would print the whole dump to the stdout:

adb exec-out uiautomator dump /dev/tty
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><hierarchy rotation="0"><node ...></node></hierarchy>UI hierchary dumped to: /dev/tty

get launchable activity name of package from adb

You don't need root to pull the apk files from /data/app. Sure, you might not have permissions to list the contents of that directory, but you can find the file locations of APKs with:

adb shell pm list packages -f

Then you can use adb pull:

adb pull <APK path from previous command>

and then aapt to get the information you want:

aapt dump badging <pulledfile.apk>

How to get the full name of fragments using adb shell dumpsys activity

According to the Android source, the fragment's toString() uses DebugUtils.buildShortClassTag() to print the class name.

Fragment.java

    @Override
public String toString() {
StringBuilder sb = new StringBuilder(128);
DebugUtils.buildShortClassTag(this, sb);
if (mIndex >= 0) {
sb.append(" #");
sb.append(mIndex);
}
if (mFragmentId != 0) {
sb.append(" id=0x");
sb.append(Integer.toHexString(mFragmentId));
}
if (mTag != null) {
sb.append(" ");
sb.append(mTag);
}
sb.append('}');
return sb.toString();
}

DebugUtils.java

    public static void buildShortClassTag(Object cls, StringBuilder out) {
if (cls == null) {
out.append("null");
} else {
String simpleName = cls.getClass().getSimpleName();
if (simpleName == null || simpleName.isEmpty()) {
simpleName = cls.getClass().getName();
int end = simpleName.lastIndexOf('.');
if (end > 0) {
simpleName = simpleName.substring(end+1);
}
}
out.append(simpleName);
out.append('{');
out.append(Integer.toHexString(System.identityHashCode(cls)));
}
}

We can see buildShortClassTag() uses cls.getClass().getSimpleName() to print the class name.

In conclusion, we cannot get the full name of fragments unless we change Android framework's source code and build a customized OS. But this solution is not perfect because fragments in AndroidX has their own logics to print the fragment information. AndroidX libraries are packaged inside an apk and they are also obfuscated.

Get info of current visible fragment(s) in android dumpsys

Check documentation with adb shell dumpsys activity -h. You can provide a <COMP_SPEC> parameter, adb shell dumpsys activity <COMP_SPEC>. When you give the <COMP_SPEC> parameter, you get more information on the specific component, including the visible fragments and views.

Example when Android device settings are displayed:

$ adb shell dumpsys activity com.android.settings

On my device, the command output contains:

...
Active Fragments in 13c3a270:
#0: DashboardSummary{186a79e9 #0 id=0x7f0e017b}
mFragmentId=#7f0e017b mContainerId=#7f0e017b mTag=null
mState=5 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
mAdded=true mRemoving=false mResumed=true mFromLayout=false mInLayout=false
mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
mRetainInstance=false mRetaining=false mUserVisibleHint=true
mFragmentManager=FragmentManager{13c3a270 in Settings{ef6d7d6}}
mActivity=com.android.settings.Settings@ef6d7d6
mContainer=android.widget.FrameLayout{9b1166e V.E..... ........ 0,0-768,1022 #7f0e017b app:id/main_content}
mView=android.widget.ScrollView{1c50410f VFED.V.. ........ 0,0-768,1022 #7f0e005a app:id/dashboard}
Child FragmentManager{2298759c in DashboardSummary{186a79e9}}:
FragmentManager misc state:
mActivity=com.android.settings.Settings@ef6d7d6
mContainer=android.app.Fragment$1@167cba5
mParent=DashboardSummary{186a79e9 #0 id=0x7f0e017b}
mCurState=5 mStateSaved=false mDestroyed=false
...


Related Topics



Leave a reply



Submit