如果您无法使用AccessibilityService的performGlobalAction(int action)方法,可能是因为您没有正确设置您的服务并在系统设置中启用了您的服务。请检查以下几点:
@Override public void onServiceConnected() { AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED | AccessibilityEvent.TYPE_VIEW_FOCUSED; info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC; info.flags = AccessibilityServiceInfo.DEFAULT; setServiceInfo(info); }
Settings -> Accessibility -> [YourAccessibilityService]
尝试完以上步骤后,您应该能够使用performGlobalAction()方法了。例如,要发送back事件:
performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);