Monkeyrunner how it gets APP of the Package Name and the Activity Name
Recent attempts to use Monkeyrunner for Android automated testing have started with the use of click-to-screen coordinates to run applications, but clicking on screen coordinates is cumbersome and less versatile. Through degrees Niang I know can use Device.startactivity ("Package name/activity") This function to directly enable the app installed on the phone, but how to get activity is the key, The methods for getting activity are summarized below:
Method 1:
1. Install the APK package on the phone first,
2. Configure the Python environment on your Android phone or simulator
1) Download and install Scripting Layer for Android (SL4A)
2) Download and install Python for Android
3) Open Python for Android app, at the top of the app there will be an install button, click the button, will automatically download the Python related files and unzip and install, after the process is over, The python development environment on your Android phone is configured!
3. Open the SL4A application, will go to the Python sample code list, is basically a demonstration of the main API, some examples may be due to the old, the runtime will prompt the method to expire or run an exception problem, this at least a little bit of code modification, there is a chance, I will describe this as an example and a revised method in a follow-up course.
Click on the Menu key, then add, select Python2.6.2, a new Python script file will be created, name the file: hellopythoninandroid.py
Click on the screen to enter the script editing area and start typing the following:
Import Android
Import Pprint
Droid=android. Android ()
Apps=droid.getlaunchableapplications ()
Pprint.pprint (Apps.result)
print '-------------------------------------'
Pacs=droid.getrunningpackages ()
Pprint.pprint (Pacs.result)
4. Click menu, select Save&run, Congratulations, run the above code, you can get the application StartActivity and package name
5., through the following program, test the APK
Import Sys
From Com.android.monkeyrunner import Monkeyrunner,monkeydevice
Device=monkeyrunner.waitforconnection ()
Device.startactivity (component= ' package name/startactivity name ')
Method 2:
Using the Re-sign.jar tool, HTTP://TROIDO.DE/DOWNLOADS/CATEGORY/1
1) Run with Java–jar D:\re-sign.jar under CMD.
2) Drag the apk bag in and the message is out.
Method 3:
Get APK Package name (pack name) and activity name via Apktool
1) Download apktool:http://code.google.com/p/android-apktool/
2) Copy the extracted three files (Apktool.jar, Aapt.exe, Apktool.bat) to the C:windows
The environment is now complete.
3) cmd enters command terminal, executes AAPT dump badging your.apk
You will see the corresponding package name, activity name.
Method 4:
View Androidmanifest.xml
1. Use Apktool to decompile app:apktool.bat D es3.apk E:\apk\es
2. Open Androidmanifest.xml
The Package property value for the manifest node is the app's bundle name: <manifest package= "Com.estrongs.android.pop" >
Find the activity that corresponds to Android.intent.action.MAIN and Android.intent.category.LAUNCHER, the activity that corresponds to Android: The Name property is both the entry activity names, as follows:
<activity android:theme= "@*android tyle/theme.notitlebar" android:label= "@string/app_name" Android:name= " Com.estrongs.android.pop.view.FileExplorerActivity ">
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Android.intent.action.MAIN determines the activity that the application starts first
Android.intent.category.LAUNCHER determines whether the application appears in the program list
Method 5:
Open your phone log, run the target program, then parse log, and you'll find the activity name in log.
Monkeyrunner How to get the app's package name and activity name