└── AutoControlWeChat
├── app
├── .gitignore
├── libs
│ └── pinyin4j-2.5.0.jar
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── xml
│ │ │ │ └── auto_control_service_config.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── yh
│ │ │ └── autocontrolwechat
│ │ │ ├── PinYinUtil.java
│ │ │ ├── MainActivity.java
│ │ │ ├── WechatUtils.java
│ │ │ └── ControlService.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── yh
│ │ │ └── autocontrolwechat
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── yh
│ │ └── autocontrolwechat
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── caches
│ └── build_file_checksums.ser
├── runConfigurations.xml
├── gradle.xml
├── misc.xml
└── codeStyles
│ └── Project.xml
├── .gitignore
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
/AutoControlWeChat/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/AutoControlWeChat/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/libs/pinyin4j-2.5.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/libs/pinyin4j-2.5.0.jar
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AutoControlWeChat
3 |
4 |
--------------------------------------------------------------------------------
/AutoControlWeChat/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/AutoControlWeChat/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HeyMouser/MyDemos_All/HEAD/AutoControlWeChat/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AutoControlWeChat/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/AutoControlWeChat/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Oct 21 10:29:31 CST 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/xml/auto_control_service_config.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/test/java/com/yh/autocontrolwechat/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yh.autocontrolwechat;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/AutoControlWeChat/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/AutoControlWeChat/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/AutoControlWeChat/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.4'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/AutoControlWeChat/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/androidTest/java/com/yh/autocontrolwechat/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.yh.autocontrolwechat;
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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.yh.autocontrolwechat", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.yh.autocontrolwechat"
7 | minSdkVersion 18
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | implementation files('libs/pinyin4j-2.5.0.jar')
29 | }
30 |
--------------------------------------------------------------------------------
/AutoControlWeChat/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 |
39 |
--------------------------------------------------------------------------------
/AutoControlWeChat/.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 |
--------------------------------------------------------------------------------
/AutoControlWeChat/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
19 |
20 |
26 |
27 |
28 |
29 |
34 |
35 |
42 |
43 |
50 |
51 |
52 |
53 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/AutoControlWeChat/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/java/com/yh/autocontrolwechat/PinYinUtil.java:
--------------------------------------------------------------------------------
1 | package com.yh.autocontrolwechat;
2 |
3 | import android.text.TextUtils;
4 |
5 | import net.sourceforge.pinyin4j.PinyinHelper;
6 | import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
7 | import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
8 | import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
9 |
10 | /**
11 | * Created by Done on 2016/11/30.
12 | */
13 | public class PinYinUtil {
14 |
15 | private HanyuPinyinOutputFormat format = null;
16 | private String[] pinyin;
17 |
18 | private PinYinUtil() {
19 | format = new HanyuPinyinOutputFormat();
20 | format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
21 | pinyin = null;
22 | }
23 |
24 | private static PinYinUtil pinYinUtil;
25 |
26 | public static PinYinUtil getPinYinUtil() {
27 | if (pinYinUtil == null)
28 | pinYinUtil = new PinYinUtil();
29 | return pinYinUtil;
30 | }
31 |
32 | /**
33 | * 转换单个字符
34 | *
35 | * @param c
36 | * @return
37 | */
38 | public String getCharacterPinYin(char c) {
39 | try {
40 | pinyin = PinyinHelper.toHanyuPinyinStringArray(c, format);
41 | } catch (BadHanyuPinyinOutputFormatCombination e) {
42 | e.printStackTrace();
43 | }
44 | // 如果c不是汉字,toHanyuPinyinStringArray会返回null
45 | if (pinyin == null) {
46 | return null;
47 | }
48 | // 只取一个发音,如果是多音字,仅取第一个发音
49 | return pinyin[0];
50 | }
51 |
52 | /**
53 | * 转换一个字符串
54 | *
55 | * @param str
56 | * @return
57 | */
58 | public String getStringPinYin(String str) {
59 | StringBuilder sb = new StringBuilder();
60 | String tempPinyin = null;
61 | if (!TextUtils.isEmpty(str)) {
62 | for (int i = 0; i < str.length(); ++i) {
63 | tempPinyin = getCharacterPinYin(str.charAt(i));
64 | if (tempPinyin == null) {
65 | // 如果str.charAt(i)非汉字,则保持原样
66 | sb.append(str.charAt(i));
67 | } else {
68 | sb.append(tempPinyin);
69 | }
70 | }
71 | return sb.toString();
72 | }
73 | return "";
74 | }
75 |
76 | /**
77 | * 提取每个汉字的首字母
78 | *
79 | * @param str
80 | * @return String
81 | */
82 | public String getPinYinHeadChar(String str) {
83 | String convert = "";
84 | for (int j = 0; j < str.length(); j++) {
85 | char word = str.charAt(j);
86 | // 提取汉字的首字母
87 | String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
88 | if (pinyinArray != null) {
89 | convert += String.valueOf(pinyinArray[0].charAt(0)).toUpperCase();
90 | } else {
91 | convert += String.valueOf(word).toUpperCase();
92 | }
93 | }
94 | return convert;
95 | }
96 |
97 | /**
98 | * 将字符串转换成ASCII码
99 | *
100 | * @param cnStr
101 | * @return String
102 | */
103 | public String getCnASCII(String cnStr) {
104 | StringBuffer strBuf = new StringBuffer();
105 | // 将字符串转换成字节序列
106 | byte[] bGBK = cnStr.getBytes();
107 | for (int i = 0; i < bGBK.length; i++) {
108 | // 将每个字符转换成ASCII码
109 | strBuf.append(Integer.toHexString(bGBK[i] & 0xff));
110 | }
111 | return strBuf.toString();
112 | }
113 | }
114 |
115 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/java/com/yh/autocontrolwechat/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yh.autocontrolwechat;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.IntentFilter;
7 | import android.os.Bundle;
8 | import android.provider.Settings;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.text.TextUtils;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.EditText;
15 | import android.widget.Toast;
16 |
17 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | private Button button;
22 | private EditText et_name, et_content;
23 | private Context mContext;
24 |
25 | private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
26 | @Override
27 | public void onReceive(Context context, Intent intent) {
28 | String action = intent.getAction();
29 | if (TextUtils.equals(action, "FIND_CONTANCT_RESULT")) {
30 | Toast.makeText(MainActivity.this, "没有找到联系人", Toast.LENGTH_LONG).show();
31 | }
32 | }
33 | };
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_main);
39 | mContext = this;
40 |
41 | registerReceiver(broadcastReceiver,new IntentFilter("FIND_CONTANCT_RESULT"));
42 |
43 | button = (Button) findViewById(R.id.button);
44 | et_name = (EditText) findViewById(R.id.et_name);
45 | et_content = (EditText) findViewById(R.id.et_content);
46 |
47 | button.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | if (isAccessibilitySettingsOn(mContext)) {
51 | String name = et_name.getText().toString().trim();
52 | String content = et_content.getText().toString().trim();
53 | ControlService.isSendSuccess = false;
54 | WechatUtils.NAME = name;
55 | WechatUtils.CONTENT = content;
56 | openWChart();
57 | } else {
58 | Intent accessibleIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
59 | startActivity(accessibleIntent);
60 | }
61 | }
62 | });
63 |
64 | }
65 |
66 |
67 | /**
68 | * 打开微信界面
69 | */
70 | private void openWChart() {
71 |
72 | Intent intent = new Intent();
73 | intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
74 | intent.setClassName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
75 | startActivity(intent);
76 |
77 | }
78 |
79 |
80 | /**
81 | * 判断微信助手是否开启
82 | *
83 | * @param context
84 | * @return
85 | */
86 | public boolean isAccessibilitySettingsOn(Context context) {
87 | int accessibilityEnabled = 0;
88 | try {
89 | accessibilityEnabled = Settings.Secure.getInt(context.getContentResolver(),
90 | Settings.Secure.ACCESSIBILITY_ENABLED);
91 | } catch (Settings.SettingNotFoundException e) {
92 | Log.i("URL", "错误信息为:" + e.getMessage());
93 | }
94 |
95 | if (accessibilityEnabled == 1) {
96 | String services = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
97 | if (services != null) {
98 | return services.toLowerCase().contains(context.getPackageName().toLowerCase());
99 | }
100 | }
101 | return false;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/AutoControlWeChat/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/java/com/yh/autocontrolwechat/WechatUtils.java:
--------------------------------------------------------------------------------
1 | package com.yh.autocontrolwechat;
2 |
3 | import android.accessibilityservice.AccessibilityService;
4 | import android.content.ClipData;
5 | import android.content.ClipboardManager;
6 | import android.content.Context;
7 | import android.os.Build;
8 | import android.os.Bundle;
9 | import android.view.accessibility.AccessibilityNodeInfo;
10 |
11 | import java.util.List;
12 |
13 | public class WechatUtils {
14 |
15 | public static String NAME;
16 | public static String CONTENT;
17 |
18 | /**
19 | * 在当前页面查找文字内容并点击
20 | *
21 | * @param text
22 | */
23 | public static void findTextAndClick(AccessibilityService accessibilityService, String text) {
24 |
25 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
26 | if (accessibilityNodeInfo == null) {
27 | return;
28 | }
29 |
30 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text);
31 | if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
32 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
33 | if (nodeInfo != null && (text.equals(nodeInfo.getText()) || text.equals(nodeInfo.getContentDescription()))) {
34 | performClick(nodeInfo);
35 | break;
36 | }
37 | }
38 | }
39 | }
40 |
41 | /**
42 | * 查找view
43 | *
44 | * @param accessibilityService
45 | * @param id
46 | */
47 | public static boolean findViewId(AccessibilityService accessibilityService, String id) {
48 |
49 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
50 | if (accessibilityNodeInfo == null) {
51 | return false;
52 | }
53 |
54 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id);
55 | return nodeInfoList != null && !nodeInfoList.isEmpty();
56 | }
57 |
58 | /**
59 | * 检查viewId进行点击
60 | *
61 | * @param accessibilityService
62 | * @param id
63 | */
64 | public static void findViewIdAndClick(AccessibilityService accessibilityService, String id) {
65 |
66 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
67 | if (accessibilityNodeInfo == null) {
68 | return;
69 | }
70 |
71 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id);
72 | if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
73 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
74 | if (nodeInfo != null) {
75 | performClick(nodeInfo);
76 | break;
77 | }
78 | }
79 | }
80 | }
81 |
82 | /**
83 | * 查找控件,并将焦点放在该空间上
84 | * @param accessibilityService
85 | * @param id
86 | */
87 | public static void findViewIdAndFouce(AccessibilityService accessibilityService, String id) {
88 |
89 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
90 | if (accessibilityNodeInfo == null) {
91 | return;
92 | }
93 |
94 | List nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id);
95 | if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
96 | for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
97 | if (nodeInfo != null) {
98 | nodeInfo.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
99 | break;
100 | }
101 | }
102 | }
103 | }
104 |
105 |
106 | /**
107 | * 根据id查找控件,并将内容粘贴上去
108 | * @param accessibilityService
109 | * @param id
110 | * @param content
111 | * @return
112 | */
113 | public static boolean findViewByIdAndPasteContent(AccessibilityService accessibilityService, String id, String content) {
114 | AccessibilityNodeInfo rootNode = accessibilityService.getRootInActiveWindow();
115 | if (rootNode != null) {
116 | List editInfo = rootNode.findAccessibilityNodeInfosByViewId(id);
117 | if (editInfo != null && !editInfo.isEmpty()) {
118 | Bundle arguments = new Bundle();
119 | arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, content);
120 | editInfo.get(0).performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
121 | return true;
122 | }
123 | return false;
124 | }
125 | return false;
126 | }
127 |
128 | /**
129 | * 根据id查找控件上的文字描述
130 | * @param accessibilityService
131 | * @param id
132 | * @return
133 | */
134 | public static String findTextById(AccessibilityService accessibilityService, String id) {
135 | AccessibilityNodeInfo rootInfo = accessibilityService.getRootInActiveWindow();
136 | if (rootInfo != null) {
137 | List userNames = rootInfo.findAccessibilityNodeInfosByViewId(id);
138 | if (userNames != null && userNames.size() > 0) {
139 | String name = userNames.get(0).getText().toString();
140 | return name;
141 | }
142 | }
143 | return null;
144 | }
145 |
146 |
147 | /**
148 | * 在当前页面查找对话框文字内容并点击
149 | *
150 | * @param text1 默认点击text1
151 | * @param text2
152 | */
153 | public static void findDialogAndClick(AccessibilityService accessibilityService, String text1, String text2) {
154 |
155 | AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
156 | if (accessibilityNodeInfo == null) {
157 | return;
158 | }
159 |
160 | List dialogWait = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text1);
161 | List dialogConfirm = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text2);
162 | if (!dialogWait.isEmpty() && !dialogConfirm.isEmpty()) {
163 | for (AccessibilityNodeInfo nodeInfo : dialogWait) {
164 | if (nodeInfo != null && text1.equals(nodeInfo.getText())) {
165 | performClick(nodeInfo);
166 | break;
167 | }
168 | }
169 | }
170 | }
171 |
172 | /**
173 | * 将内容粘贴到对应的控件上
174 | * @param accessibilityService
175 | * @param nodeInfo
176 | * @param content
177 | */
178 | public static void pastContent(AccessibilityService accessibilityService, AccessibilityNodeInfo nodeInfo, String content) {
179 | Bundle arguments = new Bundle();
180 | arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
181 | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
182 | arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true);
183 | nodeInfo.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments);
184 | nodeInfo.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
185 | ClipData clip = ClipData.newPlainText("label", content);
186 | ClipboardManager clipboardManager = (ClipboardManager) accessibilityService.getSystemService(Context.CLIPBOARD_SERVICE);
187 | clipboardManager.setPrimaryClip(clip);
188 | nodeInfo.performAction(AccessibilityNodeInfo.ACTION_PASTE);
189 | }
190 |
191 | //模拟点击事件
192 | public static void performClick(AccessibilityNodeInfo nodeInfo) {
193 | if (nodeInfo == null) {
194 | return;
195 | }
196 | if (nodeInfo.isClickable()) {
197 | nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
198 | } else {
199 | performClick(nodeInfo.getParent());
200 | }
201 | }
202 |
203 | //模拟返回事件
204 | public static void performBack(AccessibilityService service) {
205 | if (service == null) {
206 | return;
207 | }
208 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
209 | try {
210 | Thread.sleep(200);
211 | } catch (InterruptedException e) {
212 | e.printStackTrace();
213 | }
214 | service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
215 | }
216 | }
217 | }
218 |
--------------------------------------------------------------------------------
/AutoControlWeChat/app/src/main/java/com/yh/autocontrolwechat/ControlService.java:
--------------------------------------------------------------------------------
1 | package com.yh.autocontrolwechat;
2 |
3 | import android.accessibilityservice.AccessibilityService;
4 | import android.app.ActivityManager;
5 | import android.app.Notification;
6 | import android.app.PendingIntent;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.text.TextUtils;
10 | import android.util.Log;
11 | import android.view.accessibility.AccessibilityEvent;
12 | import android.view.accessibility.AccessibilityNodeInfo;
13 | import android.widget.Toast;
14 |
15 | import java.util.List;
16 |
17 | public class ControlService extends AccessibilityService {
18 | private static final String TAG = "ControlService";
19 | //微信包名
20 | private final static String WeChat_PNAME = "com.tencent.mm";
21 | //微信布局ID前缀
22 | private static final String BaseLayoutId = "com.tencent.mm:id/";
23 | //微信首页
24 | public static final String WECHAT_CLASS_LAUNCHUI = "com.tencent.mm.ui.LauncherUI";
25 | //微信聊天页面
26 | public static final String WECHAT_CLASS_CHATUI = "com.tencent.mm.ui.chatting.ChattingUI";
27 |
28 |
29 | public static boolean isSendSuccess; //true 发送完成, false 开始发送,还没发送呢
30 |
31 | //微信版本 6.7.3
32 | private String searchedittextid = "ji"; //ji
33 | private String searchlistviewid = "bp0"; // bp0
34 |
35 | /**
36 | * 聊天界面
37 | */
38 | private String chatuiedittextid = "aie"; // aep
39 | private String chatuiusernameid = "j6"; // j1
40 | private String chatuiswitchid = "aic"; // aen
41 |
42 |
43 | @Override
44 | public void onAccessibilityEvent(AccessibilityEvent event) {
45 | String className = event.getClassName().toString();
46 | Log.i(TAG, "event >> TYPE:" + event.getEventType());
47 | Log.i(TAG, "event >> ClassName:" + className);
48 |
49 | switch (event.getEventType()) {
50 | case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
51 | if (WeChat_PNAME.equals(event.getPackageName().toString())) {
52 | sendNotifacationReply(event);
53 | }
54 | break;
55 | case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
56 | //如果是主动发送消息,成功之后 就不能继续监听事件了
57 | //如果不是主动发送消息,那么 根本没必要监听这个事件,被动接收消息,都是监听通知栏变化直接跳转到聊天界面,监听TYPE_WINDOW_CONTENT_CHANGED即可
58 | if (isSendSuccess) {
59 | return;
60 | }
61 | switch (className) {
62 | case WECHAT_CLASS_LAUNCHUI:
63 | handleFlow_clickSearch();
64 | break;
65 | case WECHAT_CLASS_CHATUI:
66 | handleFlow_ChatUI();
67 | break;
68 | }
69 | break;
70 | }
71 | }
72 |
73 | @Override
74 | public void onInterrupt() {
75 |
76 | }
77 |
78 | /**
79 | * 微信界面,点击title的搜索按钮
80 | */
81 | private void handleFlow_clickSearch() {
82 | try {
83 | //如果没有名字,说明不是主动发送的,就没有必要搜索了
84 | if (TextUtils.isEmpty(WechatUtils.NAME)) return;
85 |
86 | //调起微信之后,不管在什么页面,先查找返回键并点击:防止在其他页面查找不到搜索按钮
87 | Thread.sleep(100);
88 |
89 | WechatUtils.findTextAndClick(this, "返回");
90 |
91 | Thread.sleep(500);
92 |
93 | WechatUtils.findTextAndClick(this, "搜索");
94 |
95 | Thread.sleep(500);
96 |
97 | handleFlow_past();
98 | } catch (InterruptedException e) {
99 | e.printStackTrace();
100 | }
101 | }
102 |
103 | /**
104 | * 搜索界面粘贴要搜索的内容
105 | */
106 | private void handleFlow_past() {
107 | AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
108 | if (nodeInfo != null) {
109 | List list = nodeInfo.findAccessibilityNodeInfosByViewId(BaseLayoutId + searchedittextid);
110 | if (list != null && list.size() > 0) {
111 | for (final AccessibilityNodeInfo node : list) {
112 | if (node.getClassName().equals("android.widget.EditText") && node.isEnabled()) {
113 | try {
114 | Thread.sleep(350);
115 |
116 | WechatUtils.pastContent(this, node, PinYinUtil.getPinYinUtil().getStringPinYin(WechatUtils.NAME));
117 |
118 | Thread.sleep(500);
119 |
120 | clickSearchResult();
121 | } catch (InterruptedException e) {
122 | e.printStackTrace();
123 | }
124 | break;
125 | }
126 | }
127 | }
128 | }
129 | }
130 |
131 | /**
132 | * 点击搜索到的结果
133 | */
134 | private void clickSearchResult() {
135 | AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
136 | if (nodeInfo != null) {
137 | List list1 = nodeInfo.findAccessibilityNodeInfosByViewId(BaseLayoutId + searchlistviewid);
138 | if (list1 != null && list1.size() > 0) {
139 | AccessibilityNodeInfo listInfo = list1.get(0);
140 | for (int i = 0; i < listInfo.getChildCount(); i++) {
141 | AccessibilityNodeInfo itemNodeInfo = listInfo.getChild(i);
142 | for (int j = 0; j < itemNodeInfo.getChildCount(); j++) {
143 | CharSequence name = itemNodeInfo.getChild(j).getText();
144 | Log.i(TAG, "childName:" + name);
145 | if (!TextUtils.isEmpty(name)
146 | && TextUtils.equals(PinYinUtil.getPinYinUtil().getStringPinYin(name.toString()),
147 | PinYinUtil.getPinYinUtil().getStringPinYin(WechatUtils.NAME))) {
148 | itemNodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
149 | return;
150 | }
151 | }
152 | }
153 | }
154 | }
155 | WechatUtils.NAME = "";
156 | WechatUtils.CONTENT = "";
157 | isSendSuccess = true;
158 | Log.i(TAG, "没有找到联系人");
159 | try {
160 | // 没找到联系人,一定是在搜索页面,这时候要先点一次返回 退出搜索页面,然后在退出微信
161 | // 防止直接退出微信,下一次发微信直接调起微信显示搜索页面,这时候粘贴内容就跟上一次的内容追加了,结果就不是想要的了
162 | Thread.sleep(100);
163 | WechatUtils.findTextAndClick(this, "返回");
164 | Thread.sleep(200);
165 | sendBroadcast(new Intent("FIND_CONTANCT_RESULT"));
166 | resetAndReturnApp();
167 | } catch (InterruptedException e) {
168 | e.printStackTrace();
169 | }
170 | }
171 |
172 |
173 | private void handleFlow_ChatUI() {
174 |
175 | //如果微信已经处于聊天界面,需要判断当前联系人是不是需要发送的联系人
176 | String curUserName = WechatUtils.findTextById(this, BaseLayoutId + chatuiusernameid);
177 | if (!TextUtils.isEmpty(curUserName)
178 | && TextUtils.equals(PinYinUtil.getPinYinUtil().getStringPinYin(curUserName),
179 | PinYinUtil.getPinYinUtil().getStringPinYin(WechatUtils.NAME))) {
180 | WechatUtils.NAME = "";
181 | if (TextUtils.isEmpty(WechatUtils.CONTENT)) {
182 | if (WechatUtils.findViewId(this, BaseLayoutId + chatuiedittextid)) {
183 | //当前页面可能处于发送文字状态,需要切换成发送文本状态
184 | WechatUtils.findViewIdAndClick(this, BaseLayoutId + chatuiswitchid);
185 | }
186 | isSendSuccess = true;
187 | return;
188 | }
189 | if (WechatUtils.findViewByIdAndPasteContent(this, BaseLayoutId + chatuiedittextid, WechatUtils.CONTENT)) {
190 | sendContent();
191 | } else {
192 | //当前页面可能处于发送语音状态,需要切换成发送文本状态
193 | WechatUtils.findViewIdAndClick(this, BaseLayoutId + chatuiswitchid);
194 |
195 | try {
196 | Thread.sleep(100);
197 | } catch (InterruptedException e) {
198 | e.printStackTrace();
199 | }
200 |
201 | if (WechatUtils.findViewByIdAndPasteContent(this, BaseLayoutId + chatuiedittextid, WechatUtils.CONTENT))
202 | sendContent();
203 | }
204 | } else {
205 | //回到主界面
206 | WechatUtils.findTextAndClick(this, "返回");
207 |
208 | try {
209 | Thread.sleep(200);
210 | } catch (InterruptedException e) {
211 | e.printStackTrace();
212 | }
213 | WechatUtils.findTextAndClick(this, "返回");//再次点击返回,目的是防止上一次返回到搜索页面,那样就阻塞住了
214 | }
215 | }
216 |
217 | private void sendContent() {
218 | //发送成功 能执行这一步,基本上就是发出去了
219 | WechatUtils.findTextAndClick(this, "发送");
220 | WechatUtils.NAME = "";
221 | WechatUtils.CONTENT = "";
222 | isSendSuccess = true;
223 |
224 | try {
225 | Thread.sleep(100);
226 | } catch (InterruptedException e) {
227 | e.printStackTrace();
228 | }
229 | }
230 |
231 | private void resetAndReturnApp() {
232 | isSendSuccess = true;
233 | ActivityManager activtyManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
234 | List runningTaskInfos = activtyManager.getRunningTasks(3);
235 | for (ActivityManager.RunningTaskInfo runningTaskInfo : runningTaskInfos) {
236 | if (this.getPackageName().equals(runningTaskInfo.topActivity.getPackageName())) {
237 | activtyManager.moveTaskToFront(runningTaskInfo.id, ActivityManager.MOVE_TASK_WITH_HOME);
238 | return;
239 | }
240 | }
241 | }
242 |
243 | /**
244 | * 拉起微信界面
245 | *
246 | * @param event 服务事件
247 | */
248 | private void sendNotifacationReply(AccessibilityEvent event) {
249 | if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
250 | Notification notification = (Notification) event.getParcelableData();
251 | String content = notification.tickerText.toString();
252 | String[] cc = content.split(":");
253 |
254 | String receiveName = cc[0].trim();
255 | String receciveScontent = cc[1].trim();
256 |
257 | PendingIntent pendingIntent = notification.contentIntent;
258 | try {
259 | isSendSuccess = true;
260 | pendingIntent.send();
261 | } catch (PendingIntent.CanceledException e) {
262 | e.printStackTrace();
263 | }
264 | Toast.makeText(this, content, Toast.LENGTH_LONG).show();
265 | }
266 | }
267 | }
268 |
--------------------------------------------------------------------------------