├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── linhao │ │ └── inspectwechatfriend │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── linhao │ │ │ └── inspectwechatfriend │ │ │ ├── Preferences.java │ │ │ ├── accessibility │ │ │ └── InspectWechatFriendService.java │ │ │ ├── activity │ │ │ ├── DeleteFriendListActivity.java │ │ │ └── MainActivity.java │ │ │ └── utils │ │ │ ├── PerformClickUtils.java │ │ │ └── Utils.java │ └── res │ │ ├── layout │ │ ├── activity_delete_friend_list.xml │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ ├── dimens.xml │ │ └── strings.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── inspect_wechat_friend.xml │ └── test │ └── java │ └── linhao │ └── inspectwechatfriend │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── wxid_ui.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | InspectWechatFriend -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InspectWechatFriend 2 | 检测微信是否有删除好友,目前只适配了6.3.32版本的,在android studio上导入,运行程序后点击开始检测,如果手机没有开启无障碍服务,则会调到设置页面进行打开无障碍服务,该app主要是用到了AccessibilityService 界面的ui控件的检测使用的是Google自带的uiautomatorviewer 3 | ![](https://github.com/linhaosheng/InspectWechatFriend/blob/master/wxid_ui.png) 4 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "linhao.inspectwechatfriend" 9 | minSdkVersion 21 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.0.1' 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/linhao/inspectwechatfriend/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package linhao.inspectwechatfriend; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/linhao/inspectwechatfriend/Preferences.java: -------------------------------------------------------------------------------- 1 | package linhao.inspectwechatfriend; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import java.util.ArrayList; 6 | import java.util.HashSet; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | import linhao.inspectwechatfriend.accessibility.InspectWechatFriendService; 11 | 12 | /** 13 | * Created by linhao on 16/12/30. 14 | */ 15 | 16 | public class Preferences { 17 | 18 | public static void saveDeleteFriends(Context context) { 19 | SharedPreferences sharedPreferences = context.getSharedPreferences("delete", Context.MODE_PRIVATE); 20 | sharedPreferences.edit().putStringSet("delete_friends", InspectWechatFriendService.deleteList).apply(); 21 | } 22 | 23 | 24 | public static List getDeleteFriends(Context context){ 25 | SharedPreferences sharedPreferences = context.getSharedPreferences("delete", Context.MODE_PRIVATE); 26 | Set hashSet = sharedPreferences.getStringSet("delete_friends",new HashSet()); 27 | List stringList = new ArrayList<>(); 28 | for(String s:hashSet){ 29 | stringList.add(s); 30 | } 31 | return stringList; 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/linhao/inspectwechatfriend/accessibility/InspectWechatFriendService.java: -------------------------------------------------------------------------------- 1 | package linhao.inspectwechatfriend.accessibility; 2 | 3 | import android.accessibilityservice.AccessibilityService; 4 | import android.content.Intent; 5 | import android.util.Log; 6 | import android.view.accessibility.AccessibilityEvent; 7 | import android.view.accessibility.AccessibilityNodeInfo; 8 | import android.widget.Toast; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.HashSet; 12 | import java.util.List; 13 | 14 | import linhao.inspectwechatfriend.Preferences; 15 | import linhao.inspectwechatfriend.activity.DeleteFriendListActivity; 16 | import linhao.inspectwechatfriend.utils.PerformClickUtils; 17 | import linhao.inspectwechatfriend.utils.Utils; 18 | 19 | import static android.content.ContentValues.TAG; 20 | /** 21 | * Created by linhao on 16/12/30. 22 | */ 23 | 24 | public class InspectWechatFriendService extends AccessibilityService { 25 | 26 | public static final int GROUP_COUNT = 39;//群组成员个数 27 | 28 | public static final String WECHAT_VERSION_32 = "6.3.32"; 29 | 30 | public static List nickNameList = new ArrayList<>(); 31 | public static HashSet deleteList = new HashSet<>(); 32 | public static HashSet sortItems = new HashSet<>(); 33 | 34 | public static boolean hasComplete = false; 35 | public static boolean complete = false; 36 | public static boolean canChecked; 37 | 38 | public static String selectUI_listview_id = "com.tencent.mm:id/en"; 39 | public static String selectUI_checkbox_id = "com.tencent.mm:id/n3"; 40 | public static String selectUI_sortitem_id = "com.tencent.mm:id/a90"; 41 | public static String selectUI_nickname_id = "com.tencent.mm:id/lm"; 42 | public static String selectUI_create_button_id = "com.tencent.mm:id/g9"; 43 | public static String chattingUI_message_id = "com.tencent.mm:id/bfx"; 44 | public static String groupinfoUI_listview_id = "android:id/list"; 45 | private Intent intent = null; 46 | 47 | @Override 48 | protected void onServiceConnected() {//辅助服务被打开后 执行此方法 49 | super.onServiceConnected(); 50 | Toast.makeText(this, "_已开启检测好友服务_", Toast.LENGTH_LONG).show(); 51 | intent = new Intent(this, DeleteFriendListActivity.class); 52 | String wechatVersion = Utils.getVersion(this); 53 | if (WECHAT_VERSION_32.equals(wechatVersion)) { 54 | selectUI_listview_id = "com.tencent.mm:id/en"; 55 | selectUI_checkbox_id = "com.tencent.mm:id/n3"; 56 | selectUI_sortitem_id = "com.tencent.mm:id/a90"; 57 | selectUI_nickname_id = "com.tencent.mm:id/lm"; 58 | selectUI_create_button_id = "com.tencent.mm:id/g9"; 59 | chattingUI_message_id = "com.tencent.mm:id/bfx"; 60 | groupinfoUI_listview_id = "android:id/list"; 61 | } 62 | } 63 | 64 | @Override 65 | public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {//监听手机当前窗口状态改变 比如 Activity 跳转,内容变化,按钮点击等事件 66 | 67 | //如果手机当前界面的窗口发送变化 68 | if (accessibilityEvent.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { 69 | 70 | //获取当前activity的类名: 71 | String currentWindowActivity = accessibilityEvent.getClassName().toString(); 72 | if (!hasComplete) { 73 | if ("com.tencent.mm.ui.contact.SelectContactUI".equals(currentWindowActivity)) { 74 | canChecked = true; 75 | createGroup(); 76 | } else if ("com.tencent.mm.ui.chatting.ChattingUI".equals(currentWindowActivity)) { 77 | getDeleteFriend(); 78 | } else if ("com.tencent.mm.plugin.chatroom.ui.ChatroomInfoUI".equals(currentWindowActivity)) { 79 | deleteGroup(); 80 | } else if ("com.tencent.mm.ui.LauncherUI".equals(currentWindowActivity)) { 81 | PerformClickUtils.findTextAndClick(this, "更多功能按钮"); 82 | try { 83 | Thread.sleep(1000); 84 | } catch (InterruptedException e) { 85 | e.printStackTrace(); 86 | } 87 | PerformClickUtils.findTextAndClick(this, "发起群聊"); 88 | } 89 | } else { 90 | nickNameList.clear(); 91 | deleteList.clear(); 92 | sortItems.clear(); 93 | if (intent != null) { 94 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 95 | startActivity(intent); 96 | stopSelf(); 97 | } 98 | intent = null; 99 | } 100 | } 101 | 102 | } 103 | 104 | /** 105 | * 模拟创建群组步骤 106 | */ 107 | private void createGroup() { 108 | AccessibilityNodeInfo accessibilityNodeInfo = getRootInActiveWindow(); 109 | if (accessibilityNodeInfo == null) { 110 | return; 111 | } 112 | List listview = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(selectUI_listview_id); 113 | int count = 0; 114 | int allCount = listview.get(0).getCollectionInfo().getRowCount() - 4; 115 | int sorltCount = sortItems.size(); 116 | Log.e("allCount---", String.valueOf(allCount)); 117 | Log.e("sorltCount---", String.valueOf(sorltCount)); 118 | if (!listview.isEmpty()) { 119 | while (canChecked) { 120 | List checkboxList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(selectUI_checkbox_id); 121 | List sortList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(selectUI_sortitem_id); 122 | 123 | for (AccessibilityNodeInfo nodeInfo : sortList) { 124 | if (nodeInfo != null && nodeInfo.getText() != null) { 125 | sortItems.add(nodeInfo.getText().toString()); 126 | } 127 | } 128 | for (AccessibilityNodeInfo nodeInfo : checkboxList) { 129 | 130 | String nickname = nodeInfo.getParent().findAccessibilityNodeInfosByViewId(selectUI_nickname_id).get(0).getText().toString(); 131 | if (!nickNameList.contains(nickname)) { 132 | nickNameList.add(nickname); 133 | PerformClickUtils.performClick(nodeInfo); 134 | count++; 135 | Log.e(TAG, "nickname = " + nickname); 136 | Log.e("count---", String.valueOf(count)); 137 | int lastCount = nickNameList.size() - listview.get(0).getCollectionInfo().getRowCount() + sortItems.size() + 4; 138 | Log.e("lastCount---", String.valueOf(lastCount)); 139 | if (count >= GROUP_COUNT || nickNameList.size() >= listview.get(0).getCollectionInfo().getRowCount() - sortItems.size() - 4) { 140 | List createButtons = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(selectUI_create_button_id); 141 | if (!createButtons.isEmpty()) { 142 | canChecked = false; 143 | PerformClickUtils.performClick(createButtons.get(0)); 144 | } 145 | if (nickNameList.size() >= listview.get(0).getCollectionInfo().getRowCount() - sortItems.size() - 4) { 146 | complete = true; 147 | System.out.println("end--------" + String.valueOf(complete)); 148 | } 149 | return; 150 | } 151 | } 152 | } 153 | listview.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); 154 | try { 155 | Thread.sleep(1000); 156 | } catch (InterruptedException e) { 157 | e.printStackTrace(); 158 | } 159 | } 160 | } 161 | } 162 | 163 | /** 164 | * 模拟获取被删好友列表步骤 165 | */ 166 | private void getDeleteFriend() { 167 | AccessibilityNodeInfo accessibilityNodeInfo = getRootInActiveWindow(); 168 | if (accessibilityNodeInfo == null) { 169 | return; 170 | } 171 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(chattingUI_message_id); 172 | 173 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) { 174 | if (nodeInfo != null && nodeInfo.getText() != null && nodeInfo.getText().toString().contains("你无法邀请未添加你为好友的用户进去群聊,请先向")) { 175 | String str = nodeInfo.getText().toString(); 176 | str = str.replace("你无法邀请未添加你为好友的用户进去群聊,请先向", ""); 177 | str = str.replace("发送朋友验证申请。对方通过验证后,才能加入群聊。", ""); 178 | String[] arr = str.split("、"); 179 | System.out.println("arr------" + arr); 180 | deleteList.addAll(Arrays.asList(arr)); 181 | Preferences.saveDeleteFriends(this); 182 | Log.e(TAG, "deleteList.size():" + deleteList.size()); 183 | Toast.makeText(this, "僵尸粉数量:" + deleteList.size(), Toast.LENGTH_SHORT).show(); 184 | break; 185 | } 186 | } 187 | PerformClickUtils.findTextAndClick(this, "聊天信息"); 188 | } 189 | 190 | /** 191 | * 退出群组步骤 192 | */ 193 | private void deleteGroup() { 194 | AccessibilityNodeInfo accessibilityNodeInfo = getRootInActiveWindow(); 195 | if (accessibilityNodeInfo == null) { 196 | return; 197 | } 198 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(groupinfoUI_listview_id); 199 | if (!nodeInfoList.isEmpty()) { 200 | boolean isDelete = false; 201 | while (true) { 202 | List deletes = nodeInfoList.get(0).findAccessibilityNodeInfosByText("删除并退出"); 203 | if (deletes != null && deletes.size() != 0) { 204 | String deleteButton = deletes.get(0).getText().toString(); 205 | if (deleteButton != null && deleteButton.equals("删除并退出")) { 206 | isDelete = true; 207 | break; 208 | } 209 | } 210 | if (!isDelete) { 211 | nodeInfoList.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); 212 | try { 213 | Thread.sleep(1000); 214 | } catch (InterruptedException e) { 215 | e.printStackTrace(); 216 | } 217 | } 218 | } 219 | PerformClickUtils.findTextAndClick(this, "删除并退出"); 220 | try { 221 | Thread.sleep(1000); 222 | } catch (InterruptedException e) { 223 | e.printStackTrace(); 224 | } 225 | PerformClickUtils.findTextAndClick(this, "离开群聊"); 226 | try { 227 | Thread.sleep(1000); 228 | PerformClickUtils.findTextAndClick(this, "离开群聊"); 229 | } catch (InterruptedException e) { 230 | e.printStackTrace(); 231 | } 232 | if (complete) { 233 | hasComplete = true; 234 | } 235 | } 236 | } 237 | 238 | @Override 239 | public void onInterrupt() {//辅助服务被关闭 执行此方法 240 | canChecked = false; 241 | Toast.makeText(this, "_检测好友服务被中断啦_", Toast.LENGTH_LONG).show(); 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /app/src/main/java/linhao/inspectwechatfriend/activity/DeleteFriendListActivity.java: -------------------------------------------------------------------------------- 1 | package linhao.inspectwechatfriend.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.ArrayAdapter; 6 | import android.widget.ListView; 7 | import android.widget.TextView; 8 | 9 | 10 | import java.util.List; 11 | 12 | import linhao.inspectwechatfriend.Preferences; 13 | import linhao.inspectwechatfriend.R; 14 | 15 | public class DeleteFriendListActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_delete_friend_list); 21 | ListView listView = (ListView) findViewById(R.id.listview); 22 | TextView textView = (TextView) findViewById(R.id.desc); 23 | 24 | List list = Preferences.getDeleteFriends(this); 25 | textView.setText("被删好友数量:"+list.size()); 26 | listView.setAdapter(new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,list)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/linhao/inspectwechatfriend/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package linhao.inspectwechatfriend.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.view.accessibility.AccessibilityManager; 9 | import android.widget.Button; 10 | import android.widget.Toast; 11 | 12 | import linhao.inspectwechatfriend.R; 13 | import linhao.inspectwechatfriend.utils.Utils; 14 | 15 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 16 | 17 | public class MainActivity extends AppCompatActivity { 18 | public static final String LauncherUI = "com.tencent.mm.ui.LauncherUI"; 19 | public static final String MM = "com.tencent.mm"; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | Log.d("MainActivity", Utils.getVersion(this)); 26 | findViewById(R.id.start).setOnClickListener(new View.OnClickListener() { 27 | @Override 28 | public void onClick(View view) { 29 | AccessibilityManager accessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE); 30 | accessibilityManager.addAccessibilityStateChangeListener(new AccessibilityManager.AccessibilityStateChangeListener() { 31 | @Override 32 | public void onAccessibilityStateChanged(boolean b) { 33 | if(b){ 34 | Intent intent = new Intent(); 35 | intent.setFlags(FLAG_ACTIVITY_NEW_TASK); 36 | intent.setClassName(MM, LauncherUI); 37 | startActivity(intent); 38 | }else{ 39 | try { 40 | //打开系统设置中辅助功能 41 | Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); 42 | startActivity(intent); 43 | Toast.makeText(MainActivity.this, "找到检测被删好友辅助,然后开启服务即可", Toast.LENGTH_LONG).show(); 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | } 49 | }); 50 | 51 | if(!accessibilityManager.isEnabled()){ 52 | try { 53 | //打开系统设置中辅助功能 54 | Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); 55 | startActivity(intent); 56 | Toast.makeText(MainActivity.this, "找到检测被删好友辅助,然后开启服务即可", Toast.LENGTH_LONG).show(); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | }else{ 61 | Intent intent = new Intent(); 62 | intent.setFlags(FLAG_ACTIVITY_NEW_TASK); 63 | intent.setClassName(MM, LauncherUI); 64 | startActivity(intent); 65 | } 66 | } 67 | }); 68 | final Button button = (Button) findViewById(R.id.getCount); 69 | button.setOnClickListener(new View.OnClickListener() { 70 | @Override 71 | public void onClick(View view) { 72 | startActivity(new Intent(MainActivity.this, DeleteFriendListActivity.class)); 73 | } 74 | }); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/linhao/inspectwechatfriend/utils/PerformClickUtils.java: -------------------------------------------------------------------------------- 1 | package linhao.inspectwechatfriend.utils; 2 | 3 | import android.accessibilityservice.AccessibilityService; 4 | import android.os.Build; 5 | import android.view.accessibility.AccessibilityNodeInfo; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by linhao on 16/12/30. 11 | */ 12 | 13 | public class PerformClickUtils { 14 | 15 | 16 | /** 17 | * 在当前页面查找文字内容并点击 18 | * 19 | * @param text 20 | */ 21 | public static void findTextAndClick(AccessibilityService accessibilityService,String text) { 22 | 23 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow(); 24 | if (accessibilityNodeInfo == null) { 25 | return; 26 | } 27 | 28 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text); 29 | if (nodeInfoList != null && !nodeInfoList.isEmpty()) { 30 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) { 31 | if (nodeInfo != null && (text.equals(nodeInfo.getText()) || text.equals(nodeInfo.getContentDescription()))) { 32 | performClick(nodeInfo); 33 | break; 34 | } 35 | } 36 | } 37 | } 38 | 39 | 40 | /** 41 | * 检查viewId进行点击 42 | * 43 | * @param accessibilityService 44 | * @param id 45 | */ 46 | public static void findViewIdAndClick(AccessibilityService accessibilityService,String id) { 47 | 48 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow(); 49 | if (accessibilityNodeInfo == null) { 50 | return; 51 | } 52 | 53 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id); 54 | if (nodeInfoList != null && !nodeInfoList.isEmpty()) { 55 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) { 56 | if (nodeInfo != null) { 57 | performClick(nodeInfo); 58 | break; 59 | } 60 | } 61 | } 62 | } 63 | /** 64 | * 在当前页面查找对话框文字内容并点击 65 | * 66 | * @param text1 默认点击text1 67 | * @param text2 68 | */ 69 | public static void findDialogAndClick(AccessibilityService accessibilityService,String text1, String text2) { 70 | 71 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow(); 72 | if (accessibilityNodeInfo == null) { 73 | return; 74 | } 75 | 76 | List dialogWait = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text1); 77 | List dialogConfirm = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text2); 78 | if (!dialogWait.isEmpty() && !dialogConfirm.isEmpty()) { 79 | for (AccessibilityNodeInfo nodeInfo : dialogWait) { 80 | if (nodeInfo != null && text1.equals(nodeInfo.getText())) { 81 | performClick(nodeInfo); 82 | break; 83 | } 84 | } 85 | } 86 | 87 | } 88 | 89 | //模拟点击事件 90 | public static void performClick(AccessibilityNodeInfo nodeInfo) { 91 | if (nodeInfo == null) { 92 | return; 93 | } 94 | if (nodeInfo.isClickable()) { 95 | nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK); 96 | } else { 97 | performClick(nodeInfo.getParent()); 98 | } 99 | } 100 | 101 | //模拟返回事件 102 | public static void performBack(AccessibilityService service) { 103 | if (service == null) { 104 | return; 105 | } 106 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 107 | try { 108 | Thread.sleep(200); 109 | } catch (InterruptedException e) { 110 | e.printStackTrace(); 111 | } 112 | service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /app/src/main/java/linhao/inspectwechatfriend/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package linhao.inspectwechatfriend.utils; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by linhao on 16/12/30. 11 | */ 12 | 13 | public class Utils { 14 | 15 | /** 16 | * 获取微信的版本号 17 | * @param context 18 | * @return 19 | */ 20 | public static String getVersion(Context context){ 21 | PackageManager packageManager = context.getPackageManager(); 22 | List packageInfoList = packageManager.getInstalledPackages(0); 23 | 24 | for(PackageInfo packageInfo:packageInfoList){ 25 | if("com.tencent.mm".equals(packageInfo.packageName)){ 26 | return packageInfo.versionName; 27 | } 28 | } 29 | return "6.3.32"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_delete_friend_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 |