Take the 2-minute tour ×

I have a simple requirement to run a set of files on url on MediaPlayer. I am writing a script to do this.

There is a variable mediapath in MainActivity.java which takes url path. Is it possible to give this variable url value using android monkeyrunner script. currently there is no device.set function to set the particular value.

My script is:

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
package = 'com.example.diagplayer'
activity = 'com.example.diagplayer.MainActivity'
file = open('filelist.txt', 'r')
rows = file.readlines()
for file_name in rows:
extra = {}
runComponent = package + '/' + activity
device.set("MediaPath","uri")//getting error here
device.touch(100, 350, MonkeyDevice.DOWN) 
device.touch(10,350, 'DOWN_AND_UP')
share|improve this question
@JonathonReinhart: FYI this is Jython, not Java. The definition of what is/is not a script is a whole can of worms. –  cdarke Feb 25 at 8:51

1 Answer 1

It would be impossible for a device.set() method to set a variable in a running Activity, which I think is your intention.

However you can set the extras of the Intent with the desired values (as you did) and then make your Activity extract them and set the variables.

share|improve this answer

Your Answer


