我正在为Android制作一个自动填充类型的辅助功能服务。我阅读了文档并进行了一些谷歌搜索,这仍然让我感到困惑。我只有一个edittext来填充文本。每当我尝试移动到下一个edittext时,它都不起作用。有没有办法一次访问所有编辑文本?任何人都有解决方案吗?
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
final int eventType = event.getEventType();
String eventText = null;
switch(eventType) {
case AccessibilityEvent.TYPE_VIEW_CLICKED:
eventText = "Clicked: ";
break;
case AccessibilityEvent.TYPE_VIEW_FOCUSED:
eventText = "Focused " + event.getItemCount() +":";
break;
}
eventText = eventText + event.getContentDescription();
System.out.println("Accessibility On Accessibility Event");
Log.i("Test", "Custom Accessibility On Accessibility Event");
// Do something nifty with this text, like speak the composed string
// back to the user.
Toast.makeText(getApplicationContext(), eventText, Toast.LENGTH_LONG).show();
//let's try this
AccessibilityNodeInfo nodeInfo = event.getSource();
if(event.getClassName().equals("android.widget.EditText")) {
Bundle arguments = new Bundle();
arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "Howdy");
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
// event.setAction(AccessibilityEvent.TYPE_TOUCH_INTERACTION_START);
}
}
@Override
public void onInterrupt() {
System.out.println("CustomAccessibility On Interrupt");
Log.i("Custom", "CustomAccessibility On Interrupt");
}
@Override
protected void onServiceConnected() {
//super.onServiceConnected();
Toast.makeText(getApplication(), "onServiceConnected", Toast.LENGTH_SHORT).show();
System.out.println("CustomAccessibility On Service Connected");
Log.i("Custom", "CustomAccessibility On Service Connected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
// Set the type of events that this service wants to listen to. Others
// won't be passed to this service.
info.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED |
AccessibilityEvent.TYPE_VIEW_FOCUSED;
// If you only want this service to work with specific applications, set their
// package names here. Otherwise, when the service is activated, it will listen
// to events from all applications.
// Set the type of feedback your service will provide.
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_VISUAL;
// Default services are invoked only if no package-specific ones are present
// for the type of AccessibilityEvent generated. This service *is*
// application-specific, so the flag isn't necessary. If this was a
// general-purpose service, it would be worth considering setting the
// DEFAULT flag.
// info.flags = AccessibilityServiceInfo.DEFAULT;
info.notificationTimeout = 100;
this.setServiceInfo(info);
}
感谢您的帮助!