EGHDK
EGHDK

Reputation: 18130

How to run monkeyrunner on an already installed .apk

I'm trying to run some commands on an application that is already installed through monkeyrunner. I've edited the sample code listed on d.android.com and I changed it to this:

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
device.installPackage('myproject/bin/MyApplication.apk')

# sets a variable with the package's internal name
package = 'com.example.myTestApp'

# sets a variable with the name of an Activity in the package
# activity = 'com.example.android.myapplication.MainActivity'

# sets the name of the component to start
runComponent = package

# Runs the component
device.startActivity(component=runComponent)

# Presses the Menu button
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)

# Takes a screenshot
result = device.takeSnapshot()

# Writes the screenshot to a file
result.writeToFile('myproject/shot1.png','png')

As you can see, I changed the code to (hopefully) open com.example.myTestApp But it doesn't open my application, but it seems it runs the commands on the current application. Any ideas?

Upvotes: 2

Views: 9770

Answers (3)

Vinothkumar Arputharaj
Vinothkumar Arputharaj

Reputation: 4569

First check whether your app is installed.

apk_path = device.shell('pm path com.xx.yy')
if apk_path.startswith('package:'):
    print "XXXYY already installed."
else:
    print "XXXYY app is not installed, installing APKs..."
    device.installPackage('D:/path to apk/yourapp.apk')

refer http://antoine-merle.com/introduction-to-the-monkey-runner-tool-2/

Upvotes: 1

sudo
sudo

Reputation: 1658

I was able to get the launch activity from an any installed apk from the play store using this method:

get launchable activity name of package from adb

adb shell pm list packages -f

Then you can use adb pull:

adb pull <APK path from previous command> <toYourDesiredLocation>

For Example:(adb pull /system/app/MyAPK.apk C:\someLocation)

and then aapt to get the information you want (aapt is currently located in ~\sdk\build-tools\android-4.3):

aapt dump badging <FromYourDesiredLocation\pulledfile.apk>

then look for launchable-activity: name='SomeActivityName'

Hope that helps someone else looking for the same thing.

Upvotes: 4

Diego Torres Milano
Diego Torres Milano

Reputation: 69396

You should specify the Activity in runComponent as

runComponent = package + "/" + activity

To get the names of the launchable Activities:

$ aapt dump badging <name>.apk | grep launchable-activity

Upvotes: 6

Related Questions