Get the current app's component via the ADB Shell Dumpsys command

Source: Internet
Author: User
Tags root access

Category: Adb2014-06-22 01:24 837 people read reviews (0) Favorite reports

ANDROIDADB Test Monkeyrunnerpython

In Android testing, it is often necessary to know the component required to start an activity, such as starting a system setting in Monkeyrunner: StartActivity (component= " Com.android.settings/com.android.settings.settings "), how to get the component?

There are the following methods:

1. With root access and view server enabled, use the Hierarchyviewer.bat tool in the Sdk/tools directory to get

2. In the Sdk/build-tools directory there is a AAPT tool that uses AAPT dump badging *.apk to obtain

3. Execute the ADB logcat-v time-s activitymanager in the cmd window, then click on the application to enter, such as click System Settings, enter the corresponding log information will be printed out, in the information to find cmp=com.android.settings/. Settings

4. Obtained through the ADB Shell Dumpsys Command, which is the approach I'm going to focus on.

Executing adb shell Dumpsys window-h in the cmd window displays the following Help content:

C:\USERS\XUXU>ADB Shell Dumpsys window-h
Window managerdump Options:
[-A] [-h] [cmd] ...
CMD May oneof:
L[ASTANR]: LASTANR information
P[policy]:p olicy State
A[animator]:animator State
S[essions]:active Sessions
D[isplays]:active Display Contents
T[okens]:token List
W[indows]:window List
CMD may also Bea NAME to dump windows. NAME May
Be a partialsubstring in a window name, a
Window hexobject identifier, or
' All ' for all windows, or
"Visible" for the visible windows.
-a:include all available server state.

We use the Windows option to execute the ADB shell dumpsys window W, and in the output we can find the component of the current application that is open, and the component always contains a slash "/", So we can use this command to get the output (into the System setup application), adb shell Dumpsyswindow W | FINDSTR/, need to escape the slash "/", in Linux need to change findstr to grep, at this time the output of the content will be more, not easy to find, and then the results of analysis, found to find the string "Name=",

Next re-executing adb shell Dumpsyswindow W | FINDSTR \ | Findstr Name=, the following results are output:

C:\USERS\XUXU>ADB Shell Dumpsyswindow W | FINDSTR \ | Findstr name=
Msurface=surface (name=com.android.settings/com.android.settings.settings)

Com.android.settings/com.android.settings.settings is the component we need.

Next, use the Python statement to get the component:

[python] view plaincopy

    1. Import  os  
    2. import  re  
    3.   
    4. def  getfocusedpackageandactivity ():   
    5.   
    6.         pattern = re.compile (r "[A-zA-Z0-9\.] +/[a-za-z0-9\.] + ")   
    7.         out = os.popen (" adb  Shell dumpsys window windows | findstr \/ | findstr name= "). Read ( )   
    8.         list = pattern.findall (out)   
    9.         component = list[0]  
    10.   
    11. one.          return  component  

print getfocusedpackageandactivity ()

Print Result: com.android.settings/com.android.settings.settings

So you can call the component passed in parameter when you use the StartActivity method in Monkeyrunner!

Attached Source: http://blog.csdn.net/gb112211/article/details/33073191

Get the current app's component via the ADB Shell Dumpsys command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.