I am trying to use accessibility, I have access to accessibility.
But I want to use access to power to stop the application,
I'm trying to use
event.getSource().findAccessibilityNodeInfosByViewId("com.android.settings:id/left_button")
On a sony mobile phone, this is the right job. But it does not work on an HTC cell phone.
How can I get the stop button identifier in each mobile phone? or other methods?
my code is below, thanks a lot
private void forceStopApplication(AccessibilityEvent event) {
if (event.getSource() != null) {
if (event.getPackageName().equals("com.android.settings")) {
List<AccessibilityNodeInfo> stop_nodes = event.getSource().findAccessibilityNodeInfosByViewId("com.android.settings:id/left_button");
if (stop_nodes!=null && !stop_nodes.isEmpty()) {
AccessibilityNodeInfo node;
for(int i=0; i<stop_nodes.size(); i++){
node = stop_nodes.get(i);
if (node.getClassName().equals("android.widget.Button")) {
if(node.isEnabled()){
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
} else {
performGlobalAction(GLOBAL_ACTION_BACK);
}
node.recycle();
}
}
}
List<AccessibilityNodeInfo> ok_nodes = null;
if(event.getText() != null && event.getText().size() == 4) {
ok_nodes = event.getSource().findAccessibilityNodeInfosByText(event.getText().get(3).toString());
}
if (ok_nodes!=null && !ok_nodes.isEmpty()) {
AccessibilityNodeInfo node;
for(int i=0; i<ok_nodes.size(); i++){
node = ok_nodes.get(i);
if (node.getClassName().equals("android.widget.Button")) {
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
Log.d("action", "click ok");
}
node.recycle();
}
}
}
}
}
source
share