好的,所以我想知道是否可以使用AccessibilityService / AccessibilityNodeInfo打开/关闭android.widget.Switch?这是我当前的代码,它可以点击屏幕上的文字,但它不会打开/关闭开关。
public void onAccessibilityEvent(AccessibilityEvent event) {
AccessibilityNodeInfo source = event.getSource();
if (source == null) {
return;
}
Log.v(TAG, "Event happened");
processUI(source);
}
当然,processUI会执行比较包,文本等所有操作,并将其全部发送到clickScreen,它实际上会点击屏幕。
protected void clickScreen(AccessibilityNodeInfo source, final String text, final String type, final int length)
{
Log.v(TAG, "Clicking: " + source + " / " + text + " / " + type + " / " + length);
if (text == null)
{
Log.v(TAG, "Text is NULL");
return;
}
List<AccessibilityNodeInfo> list = source.findAccessibilityNodeInfosByText(text);
for (AccessibilityNodeInfo node : list) {
Log.i(TAG, "SHOULD BE CLICKING: " + node);
node.performAction(4);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
list = source
.findAccessibilityNodeInfosByText(text);
for (AccessibilityNodeInfo node : list) {
Log.i(TAG, "MIGHT BE CLICKING: " + node);
node.performAction(4);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}