[英]How to perform Other app list item click using accessibility service like Voice Access app?
I am developing an application like VoiceAccess app.我正在开发类似 VoiceAccess 应用程序的应用程序。 Using accessibility service I am able to perform all clicks which are on top activity(3rd party applications).
使用可访问性服务,我能够执行所有顶级活动(第 3 方应用程序)上的点击。 But I am facing issue with ListItem clicks.
但是我遇到了 ListItem 点击的问题。 I am trying this code for FaceBook app.
我正在为 FaceBook 应用程序尝试此代码。 below is my code.
下面是我的代码。 Can any one help me on this.
任何人都可以帮我解决这个问题。
public class MyService extends AccessibilityService {
/**/
private SharedPreferences S_PREF;
private SharedPreferences.Editor editor;
private static final String TAG = MyService.class
.getSimpleName();
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
clickPerform(getRootInActiveWindow(), 0);
}
public void clickPerform(AccessibilityNodeInfo nodeInfo, final int depth) {
if (nodeInfo == null) return;
List<AccessibilityNodeInfo> list = nodeInfo
.findAccessibilityNodeInfosByViewId("com.facebook.katana:id/bookmarks_tab");
for (AccessibilityNodeInfo node : list) {
Log.i(TAG, "ViewID-: bookmarks_tab " + node.getChild(0));
if (S_PREF.getBoolean("fb_menu", false)) {
editor.putBoolean("fb_menu", false);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}
List<AccessibilityNodeInfo> list2 = nodeInfo
.findAccessibilityNodeInfosByViewId("com.facebook.katana:id/bookmarks_list");
for (AccessibilityNodeInfo node2 : list2) {
if (node2.getChild(0) != null)
if (S_PREF.getBoolean("fb_scroll_down", false)) {
editor.putBoolean("fb_scroll_down", false);
node2.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
}
editor.commit();
for (int i = 0; i < nodeInfo.getChildCount(); ++i) {
clickPerform(nodeInfo.getChild(i), depth+1);
}
}
@Override
public void onInterrupt() {
}
protected void onServiceConnected() {
S_PREF = getSharedPreferences("S_PREF", Context.MODE_PRIVATE);
editor = S_PREF.edit();
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.flags = AccessibilityServiceInfo.DEFAULT;
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
setServiceInfo(info);
Toast.makeText(getApplicationContext(), "onServiceConnected", Toast.LENGTH_SHORT).show();
}
}
Below is the VoiceAccess screen.下面是 VoiceAccess 屏幕。
When user says any number, then particular item click will be performed.
当用户说出任何数字时,将执行特定的项目点击。
I am able to get 7,8,9,10 events but from 11 onwards I am not getting list items individually.我能够获得 7、8、9、10 个事件,但从 11 个开始,我无法单独获得列表项。 My code returning listview id only.
我的代码仅返回列表视图 ID。
Thanks in advance....提前致谢....
@steveenzoleko @steveenzoleko
I got solution for this problem by myself.我自己解决了这个问题。 Here AccessibilityNodeInfo always doesn't return complete list or list size.
此处 AccessibilityNodeInfo 始终不返回完整列表或列表大小。 It returns VIEWs.
它返回视图。 It may be TextView, Button etc... Every View has multiple methods like getText(), getContentDescription(), getClassName(), getChildCount(), getViewIdResourceName() etc... here Voice Access app detecting all views and giving them some numbers.
它可能是 TextView、Button 等......每个视图都有多种方法,如 getText()、getContentDescription()、getClassName()、getChildCount()、getViewIdResourceName() 等......这里语音访问应用程序检测所有视图并给它们一些数字。 For lists, using getChildCount() method in for loop we can getChildViews/listItems.
对于列表,在 for 循环中使用 getChildCount() 方法,我们可以 getChildViews/listItems。 Ex:
例如:
AccessibilityNodeInfo node = getRootInActiveWindow();
if(node != null) {
for(int i = 0; i < node.getChildCount(); i++){
AccessibilityNodeInfo childNode = node.getChild(i);
if(childNode != null){
Log.i("childNode", "-----getText->"+childNode.getText()+"---getContentDescription-->"+childNode.getContentDescription() );
}
}
}
use getText() and getContentDescription() methods to know text of textview, button, checkbox.使用 getText() 和 getContentDescription() 方法来了解文本视图、按钮、复选框的文本。
getClassName() method retuns the view type like TextView, Button, ImageView, CheckBox etc... getClassName() 方法重新调整视图类型,如 TextView、Button、ImageView、CheckBox 等...
也许您可以使用 AccessibilityService API 7.0 中的 dispatchGesture。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.