检测微信自动删除好友

源码已上传到 https://github.com/linhaosheng/InspectWechatFriend

目前只适配了6.3.32版本的,在android studio上导入,运行程序后点击开始检测,如果手机没有开启无障碍服务,则会调到设置页面进行打开无障碍服务,该app主要是用到了AccessibilityService 界面的ui控件的检测使用的是Google自带的uiautomatorviewer

检测微信自动删除好友

通过 uiautomatorviewer  可以检测出对应的UI的文本和ID

一 : 根据文本进行点击 

public static void findTextAndClick(AccessibilityService accessibilityService,String text) {

    AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
    if (accessibilityNodeInfo == null) {
        return;
    }

    List<AccessibilityNodeInfo> nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text);
    if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
        for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
            if (nodeInfo != null && (text.equals(nodeInfo.getText()) || text.equals(nodeInfo.getContentDescription()))) {
                performClick(nodeInfo);
                break;
            }
        }
    }
}

第二 : 根据ID进行点击

public static void findViewIdAndClick(AccessibilityService accessibilityService,String id) {

    AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
    if (accessibilityNodeInfo == null) {
        return;
    }

    List<AccessibilityNodeInfo> nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id);
    if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
        for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
            if (nodeInfo != null) {
                performClick(nodeInfo);
                break;
            }
        }
    }
}

模拟点击事件 

//模拟点击事件
public static void performClick(AccessibilityNodeInfo nodeInfo) {
    if (nodeInfo == null) {
        return;
    }
    if (nodeInfo.isClickable()) {
        nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
    } else {
        performClick(nodeInfo.getParent());
    }
}

模拟下拉

listview.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);

根据手机的界面的变化做相应的操作:

public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {//监听手机当前窗口状态改变 比如 Activity 跳转,内容变化,按钮点击等事件

    //如果手机当前界面的窗口发送变化
    if (accessibilityEvent.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {

        //获取当前activity的类名:
        String currentWindowActivity = accessibilityEvent.getClassName().toString();
        if (!hasComplete) {
            if ("com.tencent.mm.ui.contact.SelectContactUI".equals(currentWindowActivity)) {
                canChecked = true;
                createGroup();
            } else if ("com.tencent.mm.ui.chatting.ChattingUI".equals(currentWindowActivity)) {
                getDeleteFriend();
            } else if ("com.tencent.mm.plugin.chatroom.ui.ChatroomInfoUI".equals(currentWindowActivity)) {
                deleteGroup();
            } else if ("com.tencent.mm.ui.LauncherUI".equals(currentWindowActivity)) {
                PerformClickUtils.findTextAndClick(this, "更多功能按钮");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                PerformClickUtils.findTextAndClick(this, "发起群聊");
            }
        } else {
            nickNameList.clear();
            deleteList.clear();
            sortItems.clear();
            if (intent != null) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                stopSelf();
            }
            intent = null;
        }
    }

}
有兴趣的欢迎start 和 fork

上一篇:MSICE界面和功能分析


下一篇:非常好的JavaScript学习资源推荐