I wrote an AccessibilityService service to control WeChat. But in the subsequent process, I encountered the following situation: some codes ran differently on an Android 4.4 machine (phone A, Huawei Honor 6, Android 4.4) and on an Android 7.0 machine (phone B, Huawei P9). Same, so 2 problems arise.
1. Run the AccessibilityService code on the mobile phone, which has the following two lines:
Log.d(TAG, "获取事件-->Log.d" + event);
Log.w(TAG, "获取事件-->Log.w" + event);
On mobile phone A, LogCat can display two Logs, but on mobile phone B, it can only display one Log.
2. When obtaining the window node:
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if(nodeInfo == null) {
Log.w(TAG, "rootWindow为空");
return ;
}
On mobile phone A (Huawei Honor 6, Android 4.4), the node information of WeChat (com.tencent.mm) can be obtained, but on mobile phone B (Huawei P9, Android 7.0), the system interface (ui. laucher) node information. Very confused.
All codes are as follows:
public class AcceServ extends AccessibilityService {
private String TAG = getClass().getSimpleName();
private boolean isFinish = false;
private int index = 1;
protected void onServiceConnected()
{
super.onServiceConnected();
Log.d(TAG, "onServiceConnected!" );
Log.w(TAG, "onServiceConnected!" );
Toast.makeText(AcceServ.this,"连接服务成功。请开启AcceServ", Toast.LENGTH_LONG).show();}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
final int eventType = event.getEventType();
Log.d(TAG, "获取事件-->" + event);
Log.w(TAG, "获取事件-->" + event);
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if(nodeInfo == null) {
Log.w(TAG, "rootWindow为空");
return ;}
do_some_thing();}
@Override
public void onInterrupt() {}
}
It shouldn’t be a problem with your code. Many things have been changed in each company’s UI System, so it’s impossible to know the real situation.
Thanks for the invitation.
I have never played with the AccessibilityService service. I want to say:
1. Do I need to enable permissions? First go to the permission management to see if the permissions are enabled.
2. Same as above, it may be a ROM problem.