我想用指定的時間長按指定的點。不幸的是,就像長按類沒有一種方法:UiDevice 我大概可以寫自己的方法,這樣的事情:Android UIAutomator長按設備
private void longClick(int x, int y, long time) {
android.graphics.Point point = new android.graphics.Point(x, y);
android.graphics.Point[] points = new android.graphics.Point[2];
points[0] = point;
points[1] = point;
getUiDevice().swipe(points, time/5); // according to documentation, each step lasts 5ms
}
或使用反射和調用longTap:
private void longClick(int x, int y) {
Field mUiAutomationBridgeField = getUiDevice().getClass().getDeclaredField("mUiAutomationBridge");
mUiAutomationBridgeField.setAccessible(true);
Object mUiAutomationBridge = mUiAutomationBridgeField.get(getUiDevice());
Field mInteractionControllerField = mUiAutomationBridge.getClass().getDeclaredField("mInteractionController");
mInteractionControllerField.setAccessible(true);
Object mInteractionController = mInteractionControllerField.get(mUiAutomationBridge);
Method longTap = mInteractionController.getClass().getDeclaredMethod("longTap", int.class, int.class);
longTap.setAccessible(true);
longTap.invoke(mInteractionController, x, y);
}
但是它不是滿意解,任何想法如何更好地做到這一點?他們爲什麼錯過這樣的方法?
看看下面的鏈接? –
請通過以下鏈接 '' –