package com.zx.redenvelopes;
import android.accessibilityservice.AccessibilityService;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Toast;
import java.util.List;
//文本类型:
// 微信text==童鞋: 恭喜发财
//红包类型:
// 微信text==童鞋: [微信红包]恭喜发财,大吉大利
public class WXEnvelopeService extends AccessibilityService {
static final String ENVELOPE_TEXT_KEY = "[微信红包]";
@SuppressLint("NewApi")
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
final int eventType = event.getEventType();
//Log.d(TAG, "微信事件--------------------------" + event.getEventType());
//通知栏事件
if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
List<CharSequence> texts = event.getText();
if (!texts.isEmpty()) {
for (CharSequence t : texts) {
String text = String.valueOf(t);
Log.v("tag", "监控微信消息==" + text);
if (text.contains(ENVELOPE_TEXT_KEY)) {
openNotification(event);
break;
}
}
}
} else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
openEnvelope(event);
} else if (eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
openEnvelopeContent(event);
}
}
/**
* 打开通知栏消息并跳转到红包页面
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openNotification(AccessibilityEvent event) {
if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {
return;
}
//以下是精华,将微信的通知栏消息打开
Notification notification = (Notification) event.getParcelableData();
PendingIntent pendingIntent = notification.contentIntent;
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private void openEnvelope(AccessibilityEvent event) {
if ("com.tencent.mm.ui.LauncherUI".equals(event.getClassName())) {
checkKeyFirst();
} else if ("com.tencent.mm.plugin.luckymoney.ui.En_fba4b94f".equals(event.getClassName())) {
checkOpen();
} else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI".equals(event.getClassName())) {
//Toast.makeText(this, "红包已经抢完--------", Toast.LENGTH_SHORT).show();
}
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private void openEnvelopeContent(AccessibilityEvent event) {
if ("android.widget.TextView".equals(event.getClassName())) {
checkKeyFirst();
} else if ("com.tencent.mm.plugin.luckymoney.ui.En_fba4b94f".equals(event.getClassName())) {
checkOpen();
} else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI".equals(event.getClassName())) {
// Toast.makeText(this, "红包已经抢完--------", Toast.LENGTH_SHORT).show();
}
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private void checkOpen() {
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if (nodeInfo == null) {
return;
}
List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("恭喜");
for (int i = list.size() - 1; i >= 0; i--) {
AccessibilityNodeInfo parent = list.get(i).getParent();
for (int j = 0; j < parent.getChildCount(); j++) {
AccessibilityNodeInfo child = parent.getChild(j);
if (child != null && child.isClickable()) {
child.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
}
}
}
}
private void checkKeyFirst() {
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if (nodeInfo == null) {
return;
}
List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("领取红包");
if (list.isEmpty()) {
return;
}
for (int i = list.size() - 1; i >= 0; i--) {
AccessibilityNodeInfo parent = list.get(i).getParent();
if (parent != null) {
parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
}
}
}
@Override
public void onInterrupt() {
Toast.makeText(this, "微信抢红包服务已关闭", Toast.LENGTH_SHORT).show();
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Toast.makeText(this, "微信抢红包服务已开启", Toast.LENGTH_SHORT).show();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
自动抢微信QQ红包, 自动抢房
共41个文件
png:11个
xml:11个
java:6个
4星 · 超过85%的资源 需积分: 50 130 下载量 14 浏览量
2018-01-19
12:09:21
上传
评论 9
收藏 308KB ZIP 举报
温馨提示
自动抢微信QQ红包, 自动抢房
资源推荐
资源详情
资源评论
收起资源包目录
Redenvelopes.zip (41个子文件)
Redenvelopes
gradlew.bat 2KB
gradlew 5KB
gradle.properties 747B
app
proguard-rules.pro 772B
src
test
java
com
zx
redenvelopes
ExampleUnitTest.java 413B
androidTest
java
com
zx
redenvelopes
ExampleInstrumentedTest.java 765B
main
res
mipmap-xxxhdpi
ic_launcher.png 9KB
ic_launcher_round.png 15KB
drawable
ic_launcher_background.xml 6KB
mipmap-hdpi
ic_launcher.png 3KB
ic_launcher_round.png 5KB
drawable-v24
ic_launcher_foreground.xml 2KB
values
colors.xml 214B
strings.xml 155B
styles.xml 394B
mipmap-xxhdpi
ic_launcher.png 6KB
open.jpg 31KB
ic_launcher_round.png 10KB
opento.png 123KB
mipmap-mdpi
ic_launcher.png 2KB
ic_launcher_round.png 3KB
mipmap-xhdpi
ic_launcher.png 4KB
ic_launcher_round.png 7KB
timg.jpg 20KB
mipmap-anydpi-v26
ic_launcher_round.xml 276B
ic_launcher.xml 276B
layout
activity_main.xml 1KB
xml
envelope_service_config_wx.xml 594B
envelope_service_config_qq.xml 699B
java
com
zx
redenvelopes
QQEnvelopeService.java 4KB
WXEnvelopeService.java 5KB
MainActivity.java 1KB
Types.java 1KB
AndroidManifest.xml 2KB
.gitignore 8B
build.gradle 952B
libs
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 236B
.gitignore 127B
settings.gradle 16B
build.gradle 573B
共 41 条
- 1
资源评论
- zhaohpo2018-02-02比较简单,可以参考以下
- yisheng1632019-04-30不太行呀,需要改进下。
- tang05752018-03-21不太行,还是需要改进啊,亲
- haopiqwe2018-11-28没有想象中那么有用,需要改进
- egxokey2019-04-23参考一下..
哆啦A梦z
- 粉丝: 4556
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功