android="
android:
accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged"
android:
accessibilityFeedbackType="feedbackGeneric"
android:
accessibilityFlags=""
android:
canRetrieveWindowContent="true"
android:
description="@string/accessibility_description"
android:
notificationTimeout="100"
android:
packageNames="com.tencent.mm"/>
activity_main.xml
android="
xmlns:
tools="
android:
layout_width="match_parent"
android:
layout_height="match_parent"
android:
paddingBottom="@dimen/activity_vertical_margin"
android:
paddingLeft="@dimen/activity_horizontal_margin"
android:
paddingRight="@dimen/activity_horizontal_margin"
android:
paddingTop="@dimen/activity_vertical_margin"
tools:
context=".MainActivity">
*
*抢红包外挂服务
*/
publicclassEnvelopeServiceextendsAccessibilityService{
staticfinalStringTAG="Jackie";
/**
*微信的包名
*/
staticfinalStringWECHAT_PACKAGENAME="com.tencent.mm";
/**
*红包消息的关键字
*/
staticfinalStringENVELOPE_TEXT_KEY="[微信红包]";
Handlerhandler=newHandler();
@Override
publicvoidonAccessibilityEvent(AccessibilityEventevent){
finalinteventType=event.getEventType();
Log.d(TAG,"事件---->"+event);
//通知栏事件
if(eventType==AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){
Listtexts=event.getText();
if(!
texts.isEmpty()){
for(CharSequencet:
texts){
Stringtext=String.valueOf(t);
if(text.contains(ENVELOPE_TEXT_KEY)){
openNotification(event);
break;
}
}
}
}elseif(eventType==AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED){
openEnvelope(event);
}
}
/*@Override
protectedbooleanonKeyEvent(KeyEventevent){
//returnsuper.onKeyEvent(event);
returntrue;
}*/
@Override
publicvoidonInterrupt(){
Toast.makeText(this,"中断抢红包服务",Toast.LENGTH_SHORT).show();
}
@Override
protectedvoidonServiceConnected(){
super.onServiceConnected();
Toast.makeText(this,"连接抢红包服务",Toast.LENGTH_SHORT).show();
}
privatevoidsendNotificationEvent(){
AccessibilityManagermanager=(AccessibilityManager)getSystemService(ACCESSIBILITY_SERVICE);
if(!
manager.isEnabled()){
return;
}
AccessibilityEventevent=AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
event.setPackageName(WECHAT_PACKAGENAME);
event.setClassName(Notification.class.getName());
CharSequencetickerText=ENVELOPE_TEXT_KEY;
event.getText().add(tickerText);
manager.sendAccessibilityEvent(event);
}
/**
*打开通知栏消息
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
privatevoidopenNotification(AccessibilityEventevent){
if(event.getParcelableData()==null||!
(event.getParcelableData()instanceofNotification)){
return;
}
//以下是精华,将微信的通知栏消息打开
Notificationnotification=(Notification)event.getParcelableData();
PendingIntentpendingIntent=notification.contentIntent;
try{
pendingIntent.send();
}catch(PendingIntent.CanceledExceptione){
e.printStackTrace();
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
privatevoidopenEnvelope(AccessibilityEventevent){
if("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI".equals(event.getClassName())){
//点中了红包,下一步就是去拆红包
checkKey1();
}elseif("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI".equals(event.getClassName())){
//拆完红包后看详细的纪录界面
//nonething
}elseif("com.tencent.mm.ui.LauncherUI".equals(event.getClassName())){
//在聊天界面,去点中红包
checkKey2();
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
privatevoidcheckKey1(){
AccessibilityNodeInfonodeInfo=getRootInActiveWindow();
if(nodeInfo==null){
Log.w(TAG,"rootWindow为空");
return;
}
Listlist=nodeInfo.findAccessibilityNodeInfosByText("拆红包");
for(AccessibilityNodeInfon:
list){
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
privatevoidcheckKey2(){
AccessibilityNodeInfonodeInfo=getRootInActiveWindow();
if(nodeInfo==null){
Log.w(TAG,"rootWindow为空");
return;
}
Listlist=nodeInfo.findAccessibilityNodeInfosByText("领取红包");
if(list.isEmpty()){
list=nodeInfo.findAccessibilityNodeInfosByText(ENVELOPE_TEXT_KEY);
for(AccessibilityNodeInfon:
list){
Log.i(TAG,"-->微信红包:
"+n);
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
}
}else{
//最新的红包领起
for(inti=list.size()-1;i>=0;i--){
AccessibilityNodeInfoparent=list.get(i).getParent();
Log.i(TAG,"-->领取红包:
"+parent);
if(parent!
=null){
parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
}
}
}
}
}