search

Home  >  Q&A  >  body text

Why does the same code display different results on different versions of Android phones?

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() {}
  
}

phpcn_u1582phpcn_u15822711 days ago1031

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-06-17 09:18:14

    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.

    reply
    0
  • 为情所困

    为情所困2017-06-17 09:18:14

    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.

    reply
    0
  • Cancelreply