├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── clearlee
│ │ └── autosendwechatmsg
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── clearlee
│ │ │ └── autosendwechatmsg
│ │ │ ├── AutoSendMsgService.java
│ │ │ ├── MainActivity.java
│ │ │ ├── WeChatTextWrapper.java
│ │ │ └── WechatUtils.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── auto_reply_service_config.xml
│ └── test
│ └── java
│ └── com
│ └── clearlee
│ └── autosendwechatmsg
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.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/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AutoSendWeChatMsg
2 | 模拟自动发送微信消息
3 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.0"
6 | defaultConfig {
7 | applicationId "com.clearlee.autosendwechatmsg"
8 | minSdkVersion 18
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/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 D:\android\AndroidSdk/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/clearlee/autosendwechatmsg/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.clearlee.autosendwechatmsg;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.clearlee.autosendwechatmsg", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
28 |
29 |
30 |
31 |
32 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clearlee/autosendwechatmsg/AutoSendMsgService.java:
--------------------------------------------------------------------------------
1 | package com.clearlee.autosendwechatmsg;
2 |
3 | import android.accessibilityservice.AccessibilityService;
4 | import android.app.ActivityManager;
5 | import android.content.Context;
6 | import android.text.TextUtils;
7 | import android.util.Log;
8 | import android.view.accessibility.AccessibilityEvent;
9 | import android.view.accessibility.AccessibilityNodeInfo;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by Clearlee
16 | * 2017/12/22.
17 | */
18 | public class AutoSendMsgService extends AccessibilityService {
19 |
20 | private static final String TAG = "AutoSendMsgService";
21 | private List allNameList = new ArrayList<>();
22 | private int mRepeatCount;
23 |
24 | public static boolean hasSend;
25 | public static final int SEND_FAIL = 0;
26 | public static final int SEND_SUCCESS = 1;
27 | public static int SEND_STATUS;
28 |
29 | /**
30 | * 必须重写的方法,响应各种事件。
31 | *
32 | * @param event
33 | */
34 | @Override
35 | public void onAccessibilityEvent(final AccessibilityEvent event) {
36 | int eventType = event.getEventType();
37 | switch (eventType) {
38 | case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: {
39 |
40 | String currentActivity = event.getClassName().toString();
41 |
42 | if (hasSend) {
43 | return;
44 | }
45 |
46 | if (currentActivity.equals(WeChatTextWrapper.WechatClass.WECHAT_CLASS_LAUNCHUI)) {
47 | handleFlow_LaunchUI();
48 | } else if (currentActivity.equals(WeChatTextWrapper.WechatClass.WECHAT_CLASS_CONTACTINFOUI)) {
49 | handleFlow_ContactInfoUI();
50 | } else if (currentActivity.equals(WeChatTextWrapper.WechatClass.WECHAT_CLASS_CHATUI)) {
51 | handleFlow_ChatUI();
52 | }
53 | }
54 | break;
55 | }
56 | }
57 |
58 | private void handleFlow_ChatUI() {
59 |
60 | //如果微信已经处于聊天界面,需要判断当前联系人是不是需要发送的联系人
61 | String curUserName = WechatUtils.findTextById(this, WeChatTextWrapper.WechatId.WECHATID_CHATUI_USERNAME_ID);
62 | if (!TextUtils.isEmpty(curUserName) && curUserName.equals(WechatUtils.NAME)) {
63 | if (WechatUtils.findViewByIdAndPasteContent(this, WeChatTextWrapper.WechatId.WECHATID_CHATUI_EDITTEXT_ID, WechatUtils.CONTENT)) {
64 | sendContent();
65 | } else {
66 | //当前页面可能处于发送语音状态,需要切换成发送文本状态
67 | WechatUtils.findViewIdAndClick(this, WeChatTextWrapper.WechatId.WECHATID_CHATUI_SWITCH_ID);
68 |
69 | try {
70 | Thread.sleep(100);
71 | } catch (InterruptedException e) {
72 | e.printStackTrace();
73 | }
74 |
75 | if (WechatUtils.findViewByIdAndPasteContent(this, WeChatTextWrapper.WechatId.WECHATID_CHATUI_EDITTEXT_ID, WechatUtils.CONTENT)) {
76 | sendContent();
77 | }
78 | }
79 | } else {
80 | //回到主界面
81 | WechatUtils.findViewIdAndClick(this, WeChatTextWrapper.WechatId.WECHATID_CHATUI_BACK_ID);
82 | }
83 | }
84 |
85 | private void handleFlow_ContactInfoUI() {
86 | WechatUtils.findTextAndClick(this, "发消息");
87 | }
88 |
89 | private void handleFlow_LaunchUI() {
90 |
91 | try {
92 | //点击通讯录,跳转到通讯录页面
93 | WechatUtils.findTextAndClick(this, "通讯录");
94 |
95 | Thread.sleep(50);
96 |
97 | //再次点击通讯录,确保通讯录列表移动到了顶部
98 | WechatUtils.findTextAndClick(this, "通讯录");
99 |
100 | Thread.sleep(200);
101 |
102 | //遍历通讯录联系人列表,查找联系人
103 | AccessibilityNodeInfo itemInfo = TraversalAndFindContacts();
104 | if (itemInfo != null) {
105 | WechatUtils.performClick(itemInfo);
106 | } else {
107 | SEND_STATUS = SEND_FAIL;
108 | resetAndReturnApp();
109 | }
110 |
111 | } catch (Exception e) {
112 | e.printStackTrace();
113 | }
114 |
115 | }
116 |
117 | /**
118 | * 从头至尾遍历寻找联系人
119 | *
120 | * @return
121 | */
122 | private AccessibilityNodeInfo TraversalAndFindContacts() {
123 |
124 | if (allNameList != null) allNameList.clear();
125 |
126 | AccessibilityNodeInfo rootNode = getRootInActiveWindow();
127 | List listview = rootNode.findAccessibilityNodeInfosByViewId(WeChatTextWrapper.WechatId.WECHATID_CONTACTUI_LISTVIEW_ID);
128 |
129 | //是否滚动到了底部
130 | boolean scrollToBottom = false;
131 | if (listview != null && !listview.isEmpty()) {
132 | while (true) {
133 | //获取当前屏幕上的联系人信息
134 | List nameList = rootNode.findAccessibilityNodeInfosByViewId(WeChatTextWrapper.WechatId.WECHATID_CONTACTUI_NAME_ID);
135 | List itemList = rootNode.findAccessibilityNodeInfosByViewId(WeChatTextWrapper.WechatId.WECHATID_CONTACTUI_ITEM_ID);
136 |
137 | if (nameList != null && !nameList.isEmpty()) {
138 | for (int i = 0; i < nameList.size(); i++) {
139 | if (i == 0) {
140 | //必须在一个循环内,防止翻页的时候名字发生重复
141 | mRepeatCount = 0;
142 | }
143 | AccessibilityNodeInfo itemInfo = itemList.get(i);
144 | AccessibilityNodeInfo nodeInfo = nameList.get(i);
145 | String nickname = nodeInfo.getText().toString();
146 | Log.d(TAG, "nickname = " + nickname);
147 | if (nickname.equals(WechatUtils.NAME)) {
148 | return itemInfo;
149 | }
150 | if (!allNameList.contains(nickname)) {
151 | allNameList.add(nickname);
152 | } else if (allNameList.contains(nickname)) {
153 | Log.d(TAG, "mRepeatCount = " + mRepeatCount);
154 | if (mRepeatCount == 3) {
155 | //表示已经滑动到顶部了
156 | if (scrollToBottom) {
157 | Log.d(TAG, "没有找到联系人");
158 | //此次发消息操作已经完成
159 | hasSend = true;
160 | return null;
161 | }
162 | scrollToBottom = true;
163 | }
164 | mRepeatCount++;
165 | }
166 | }
167 | }
168 |
169 | if (!scrollToBottom) {
170 | //向下滚动
171 | listview.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
172 | } else {
173 | return null;
174 | }
175 |
176 | //必须等待,因为需要等待滚动操作完成
177 | try {
178 | Thread.sleep(500);
179 | } catch (InterruptedException e) {
180 | e.printStackTrace();
181 | }
182 | }
183 | }
184 | return null;
185 | }
186 |
187 | private void sendContent() {
188 | WechatUtils.findTextAndClick(this, "发送");
189 | SEND_STATUS = SEND_SUCCESS;
190 | resetAndReturnApp();
191 | }
192 |
193 | private void resetAndReturnApp() {
194 | hasSend = true;
195 | ActivityManager activtyManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
196 | List runningTaskInfos = activtyManager.getRunningTasks(3);
197 | for (ActivityManager.RunningTaskInfo runningTaskInfo : runningTaskInfos) {
198 | if (this.getPackageName().equals(runningTaskInfo.topActivity.getPackageName())) {
199 | activtyManager.moveTaskToFront(runningTaskInfo.id, ActivityManager.MOVE_TASK_WITH_HOME);
200 | return;
201 | }
202 | }
203 | }
204 |
205 | @Override
206 | public void onInterrupt() {
207 |
208 | }
209 |
210 |
211 | }
212 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clearlee/autosendwechatmsg/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.clearlee.autosendwechatmsg;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.text.TextUtils;
9 | import android.view.View;
10 | import android.view.accessibility.AccessibilityManager;
11 | import android.widget.EditText;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
16 | import static com.clearlee.autosendwechatmsg.AutoSendMsgService.SEND_STATUS;
17 | import static com.clearlee.autosendwechatmsg.AutoSendMsgService.SEND_SUCCESS;
18 | import static com.clearlee.autosendwechatmsg.AutoSendMsgService.hasSend;
19 | import static com.clearlee.autosendwechatmsg.WechatUtils.CONTENT;
20 | import static com.clearlee.autosendwechatmsg.WechatUtils.NAME;
21 |
22 | /**
23 | * Created by Clearlee
24 | * 2017/12/22.
25 | */
26 | public class MainActivity extends AppCompatActivity {
27 |
28 | private TextView start, sendStatus;
29 | private EditText sendName, sendContent;
30 | private AccessibilityManager accessibilityManager;
31 | private String name, content;
32 |
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_main);
38 | init();
39 | }
40 |
41 | private void init() {
42 | start = (TextView) findViewById(R.id.testWechat);
43 | sendName = (EditText) findViewById(R.id.sendName);
44 | sendContent = (EditText) findViewById(R.id.sendContent);
45 | sendStatus = (TextView) findViewById(R.id.sendStatus);
46 | start.setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | checkAndStartService();
50 | }
51 | });
52 | }
53 |
54 | private int goWecaht() {
55 | try {
56 | setValue(name, content);
57 | hasSend = false;
58 | Intent intent = new Intent();
59 | intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
60 | intent.setClassName(WeChatTextWrapper.WECAHT_PACKAGENAME, WeChatTextWrapper.WechatClass.WECHAT_CLASS_LAUNCHUI);
61 | startActivity(intent);
62 |
63 | while (true) {
64 | if (hasSend) {
65 | return SEND_STATUS;
66 | } else {
67 | try {
68 | Thread.sleep(500);
69 | } catch (Exception e) {
70 | openService();
71 | e.printStackTrace();
72 | }
73 | }
74 | }
75 |
76 | } catch (Exception e) {
77 | e.printStackTrace();
78 | return SEND_STATUS;
79 | }
80 | }
81 |
82 |
83 | private void openService() {
84 | try {
85 | //打开系统设置中辅助功能
86 | Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
87 | startActivity(intent);
88 | Toast.makeText(MainActivity.this, "找到微信自动发送消息,然后开启服务即可", Toast.LENGTH_LONG).show();
89 | } catch (Exception e) {
90 | e.printStackTrace();
91 | }
92 | }
93 |
94 | private void checkAndStartService() {
95 | accessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
96 |
97 | name = sendName.getText().toString();
98 | content = sendContent.getText().toString();
99 |
100 | if (TextUtils.isEmpty(name)) {
101 | Toast.makeText(MainActivity.this, "联系人不能为空", Toast.LENGTH_SHORT);
102 | }
103 | if (TextUtils.isEmpty(content)) {
104 | Toast.makeText(MainActivity.this, "内容不能为空", Toast.LENGTH_SHORT);
105 | }
106 |
107 | if (!accessibilityManager.isEnabled()) {
108 | openService();
109 | } else {
110 | new Thread(new Runnable() {
111 | @Override
112 | public void run() {
113 | statusHandler.sendEmptyMessage(goWecaht());
114 | }
115 | }).start();
116 | }
117 | }
118 |
119 | Handler statusHandler = new Handler() {
120 | @Override
121 | public void handleMessage(Message msg) {
122 | super.handleMessage(msg);
123 | setSendStatusText(msg.what);
124 | }
125 | };
126 |
127 | private void setSendStatusText(int status) {
128 | if (status == SEND_SUCCESS) {
129 | sendStatus.setText("微信发送成功");
130 | } else {
131 | sendStatus.setText("微信发送失败");
132 | }
133 | }
134 |
135 | public void setValue(String name, String content) {
136 | NAME = name;
137 | CONTENT = content;
138 | hasSend = false;
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clearlee/autosendwechatmsg/WeChatTextWrapper.java:
--------------------------------------------------------------------------------
1 | package com.clearlee.autosendwechatmsg;
2 |
3 | /**
4 | * Created by Clearlee on 2017/12/22 0023.
5 | * 微信版本6.6.0
6 | */
7 |
8 | public class WeChatTextWrapper {
9 |
10 | public static final String WECAHT_PACKAGENAME = "com.tencent.mm";
11 |
12 |
13 | public static class WechatClass{
14 | //微信首页
15 | public static final String WECHAT_CLASS_LAUNCHUI = "com.tencent.mm.ui.LauncherUI";
16 | //微信联系人页面
17 | public static final String WECHAT_CLASS_CONTACTINFOUI = "com.tencent.mm.plugin.profile.ui.ContactInfoUI";
18 | //微信聊天页面
19 | public static final String WECHAT_CLASS_CHATUI = "com.tencent.mm.ui.chatting.ChattingUI";
20 | }
21 |
22 |
23 | public static class WechatId{
24 | /**
25 | * 通讯录界面
26 | */
27 | public static final String WECHATID_CONTACTUI_LISTVIEW_ID = "com.tencent.mm:id/ih";
28 | public static final String WECHATID_CONTACTUI_ITEM_ID = "com.tencent.mm:id/iy";
29 | public static final String WECHATID_CONTACTUI_NAME_ID = "com.tencent.mm:id/j1";
30 |
31 | /**
32 | * 聊天界面
33 | */
34 | public static final String WECHATID_CHATUI_EDITTEXT_ID = "com.tencent.mm:id/a_z";
35 | public static final String WECHATID_CHATUI_USERNAME_ID = "com.tencent.mm:id/ha";
36 | public static final String WECHATID_CHATUI_BACK_ID = "com.tencent.mm:id/h9";
37 | public static final String WECHATID_CHATUI_SWITCH_ID = "com.tencent.mm:id/a_x";
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clearlee/autosendwechatmsg/WechatUtils.java:
--------------------------------------------------------------------------------
1 | package com.clearlee.autosendwechatmsg;
2 |
3 | import android.accessibilityservice.AccessibilityService;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.view.accessibility.AccessibilityNodeInfo;
7 |
8 | import java.util.List;
9 |
10 |
11 | /**
12 | * Created by Clearlee
13 | * 2017/12/22.
14 | */
15 | public class WechatUtils {
16 |
17 | public static String NAME;
18 | public static String CONTENT;
19 |
20 | /**
21 | * 在当前页面查找文字内容并点击
22 | *
23 | * @param text
24 | */
25 | public static void findTextAndClick(AccessibilityService accessibilityService, String text) {
26 |
27 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
28 | if (accessibilityNodeInfo == null) {
29 | return;
30 | }
31 |
32 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text);
33 | if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
34 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
35 | if (nodeInfo != null && (text.equals(nodeInfo.getText()) || text.equals(nodeInfo.getContentDescription()))) {
36 | performClick(nodeInfo);
37 | break;
38 | }
39 | }
40 | }
41 | }
42 |
43 |
44 | /**
45 | * 检查viewId进行点击
46 | *
47 | * @param accessibilityService
48 | * @param id
49 | */
50 | public static void findViewIdAndClick(AccessibilityService accessibilityService, String id) {
51 |
52 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
53 | if (accessibilityNodeInfo == null) {
54 | return;
55 | }
56 |
57 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id);
58 | if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
59 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
60 | if (nodeInfo != null) {
61 | performClick(nodeInfo);
62 | break;
63 | }
64 | }
65 | }
66 | }
67 |
68 |
69 | public static boolean findViewByIdAndPasteContent(AccessibilityService accessibilityService, String id, String content) {
70 | AccessibilityNodeInfo rootNode = accessibilityService.getRootInActiveWindow();
71 | if (rootNode != null) {
72 | List editInfo = rootNode.findAccessibilityNodeInfosByViewId(id);
73 | if (editInfo != null && !editInfo.isEmpty()) {
74 | Bundle arguments = new Bundle();
75 | arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, content);
76 | editInfo.get(0).performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
77 | return true;
78 | }
79 | return false;
80 | }
81 | return false;
82 | }
83 |
84 | public static String findTextById(AccessibilityService accessibilityService, String id) {
85 | AccessibilityNodeInfo rootInfo = accessibilityService.getRootInActiveWindow();
86 | if (rootInfo != null) {
87 | List userNames = rootInfo.findAccessibilityNodeInfosByViewId(id);
88 | if (userNames != null && userNames.size() > 0) {
89 | String name = userNames.get(0).getText().toString();
90 | return name;
91 | }
92 | }
93 | return null;
94 | }
95 |
96 |
97 | /**
98 | * 在当前页面查找对话框文字内容并点击
99 | *
100 | * @param text1 默认点击text1
101 | * @param text2
102 | */
103 | public static void findDialogAndClick(AccessibilityService accessibilityService, String text1, String text2) {
104 |
105 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
106 | if (accessibilityNodeInfo == null) {
107 | return;
108 | }
109 |
110 | List dialogWait = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text1);
111 | List dialogConfirm = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text2);
112 | if (!dialogWait.isEmpty() && !dialogConfirm.isEmpty()) {
113 | for (AccessibilityNodeInfo nodeInfo : dialogWait) {
114 | if (nodeInfo != null && text1.equals(nodeInfo.getText())) {
115 | performClick(nodeInfo);
116 | break;
117 | }
118 | }
119 | }
120 |
121 | }
122 |
123 | //模拟点击事件
124 | public static void performClick(AccessibilityNodeInfo nodeInfo) {
125 | if (nodeInfo == null) {
126 | return;
127 | }
128 | if (nodeInfo.isClickable()) {
129 | nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
130 | } else {
131 | performClick(nodeInfo.getParent());
132 | }
133 | }
134 |
135 | //模拟返回事件
136 | public static void performBack(AccessibilityService service) {
137 | if (service == null) {
138 | return;
139 | }
140 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
141 | try {
142 | Thread.sleep(200);
143 | } catch (InterruptedException e) {
144 | e.printStackTrace();
145 | }
146 | service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
27 |
28 |
29 |
30 |
35 |
36 |
42 |
43 |
44 |
51 |
52 |
53 |
54 |
59 |
60 |
66 |
67 |
68 |
75 |
76 |
77 |
78 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 微信自动发送消息
3 | 用于自动发送微信消息
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/auto_reply_service_config.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/test/java/com/clearlee/autosendwechatmsg/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.clearlee.autosendwechatmsg;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clearlee/AutoSendWeChatMsg/27900959117e1c2cc58de665e08a3ef7c9368165/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 13 16:48:38 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------