當前位置:編程學習大全網 - 編程語言 - 如何調用AdbWinUsbApi.dll 和AdbWinApi.dll 的接口

如何調用AdbWinUsbApi.dll 和AdbWinApi.dll 的接口

[mw_shl_code=java,true]package ei.workshop.monkey.service;

import java.util.ArrayList;

import java.util.Collection;

import java.util.HashMap;

import com.android.monkeyrunner.adb.AdbBackend;

import com.android.monkeyrunner.core.IMonkeyDevice;

import com.android.monkeyrunner.core.TouchPressType;

/**

* MonkeyRunner的運行代理類,相關方法

* @see #connect(String)

* @see #touchDown(int, int)

* @see #touchUp(int, int)

* @see #type(String)

* @see #press(String)

* @see #startActivity(String)

* @see #drag(int, int, int, int)

* @see #dispose()

* @author "laladin.syd"

*

*/

public class RunnerProxy {

private IMonkeyDevice device;

private static AdbBackend adb;

public RunnerProxy() {

if (adb==null){

adb = new AdbBackend();//妳看這個是不是妳需要的,通過他可以連接到手機,然後可以對手機進行類似於豌豆莢的操作

}

}

/**

* 連接設備,

* @param deviceID 超時時間,應該盡可能短

* @return 是否連接成功

*/

public boolean connect(String deviceID) {

if (adb != null){

device = adb.waitForConnection(5000,deviceID);

System.out.println("adb 連接,得到device:"+deviceID+"="+device);

}

if (device==null) return false;

return true;

}

/**

* 釋放

*/

public void dispose() {

if (device != null) {

device.dispose();

device = null;

}

}

/**

* 摸擬touch方法

* @param x 坐標x

* @param y 坐標y

*

*/

public void touch(int x, int y,String type) {

if("DOWNANDUP".equals(type.toUpperCase())){

device.touch(x, y, TouchPressType.DOWN_AND_UP);

}else if("DOWN".equals(type.toUpperCase())){

device.touch(x, y, TouchPressType.DOWN);

}else if("UP".equals(type.toUpperCase())){

device.touch(x, y, TouchPressType.UP);

}

}

/**

* 摸擬長按

* @param x 坐標x

* @param y 坐標y

*/

public void longTouch(int x, int y) {

device.drag(x, y, x, y, 10, 2);

}

/**

* 摸擬滑動超作

* @param x

* @param y

* @param endX

* @param endY

*/

public void drag(int x, int y, int endX, int endY) {

device.drag(x, y, endX, endY, 10, 2);

}

/**

* 摸擬滑動操作

* @param x

* @param y

* @param endX

* @param endY

* @param step

* @param ms

*/

public void drag(int x, int y, int endX, int endY,int step,int ms) {

device.drag(x, y, endX, endY, 10, 2);

}

/**

* 輸入文本內容,PS:只支持英文

* @param value 要輸入的文本內容

*/

public void type(String value) {

device.type(value);

}

/**

* 同Touch方法,Down和UP連做

* @param keyCode

*/

public void press(String keyCode) {

device.press(keyCode, TouchPressType.DOWN_AND_UP);

}

/**

* 啟動壹個窗體

* @param component

*/

public void startActivity(String component) {

String action = "android.intent.action.MAIN";

Collection<String> categories = new ArrayList<String>();

categories.add("android.intent.category.LAUNCHER");

device.startActivity(null, action, null, null, categories,

new HashMap<String, Object>(), component, 0);

}

} [/mw_shl_code]

  • 上一篇:代碼編程集
  • 下一篇:使用VB.NET開發自定義Windows控件
  • copyright 2024編程學習大全網