The previous use of java to call monkeyrunner (http://fengbohaishang.blog.51cto.com/5106297/1065647) left a problem, that is, the last use of the lower version of the four packages to solve the problem, using a higher version of the jar package how to call monkeyrunner?
After a friend prompts me that the method of the higher version has changed, I searched the required classes online according to his prompt. After the test passed, summary of this supplementary article.
The four packages in lib under the android sdk tools path were used last time: ddmlib. jar, guavalib. jar, monkeyrunner. jar, sdklib. jar. the new version requires another package: chimpchat. jar, monkerunner. jar is not required. In addition, in earlier versions, IMonkeyDevice is implemented using AdbMonkeyDevice. In later versions, these two classes are not available, and AdbChimpDevice and IchimpDevice are used.
And by viewing AdbChimpDevice www.2cto.com (http://code.google.com/p/aster/source/browse/src/com/android/chimpchat/adb/AdbChimpDevice.java? R = 967f7f8cd6249c69e00c6de7ff1b55bd0f51d311) and IchimpDevice (http://code.google.com/p/aster/source/browse/src/com/android/chimpchat/core/IChimpDevice.java? R = strong) in the official source code, it is not difficult to find that AdbChimpDevice implements the IchimpDevice interface. However, the connection method still uses AdbBackend to connect the simulator or the real machine through adb. Only the parent class of the Device has changed.
We can see the differences between the two by slightly changing the test classes below:
Import java. util. ArrayList;
Import java. util. Collection;
Import java. util. HashMap;
Import com. android. chimpchat. adb. AdbBackend;
Import com. android. chimpchat. adb. AdbChimpDevice;
Public class TestNewMonkeyrunner {
/**
* @ Param args
*/
// Changes
Private static AdbChimpDevice device;
Private static AdbBackend adb;
Public static void main (String [] args ){
// TODO Auto-generated method stub
If (adb = null ){
Adb = new AdbBackend ();
// The parameters are the custom connection wait time and device id.
// Note the adb type.
Device = (AdbChimpDevice) adb. waitForConnection (8000, "MSM8225QRD5 ");
}
// Add the start permission
String action = "android. intent. action. MAIN ";
Collection <String> categories = new ArrayList <String> ();
Categories. add ("android. intent. category. LAUNCHER ");
// Start the main interface to be tested
Device. startActivity (null, action, null, null, categories,
New HashMap <String, Object> (), "cn.com. fetion/. android. ui. activities. StartActivity", 0 );
// Click a Coordinate
// The touch method is slightly changed.
Device. touch (202,258, com. android. chimpchat. core. TouchPressType. DOWN_AND_UP );
}
}
We can see from the above that there are not many changes between the high version and the low version. As long as you connect to the device, you can check the source code or rewrite some common methods.
The comments in the source code are very detailed, such as the startActivity method in the IchimpDevice interface class:
Void startActivity (@ Nullable String uri, @ Nullable String action,
@ Nullable String data, @ Nullable String mimeType,
Collection <String> categories, Map <String, Object> extras, @ Nullable String component,
Int flags );
/**
* Send a broadcast intent to the device.
*
* @ Param uri the URI for the Intent
* @ Param action the action for the Intent
* @ Param data the data URI for the Intent
* @ Param mimeType the mime type for the Intent
* @ Param categories the category names for the Intent
* @ Param extras the extras to add to the Intent
* @ Param component the component of the Intent
* @ Param flags the flags for the Intent
*/
This method clearly explains important parameters. Therefore, it is recommended that you study the issue of calling monkeyrunner in java. Do not forget the source code as the best resource.