馬上過年了,又到了紅包滿天飛的季節,emmmm...先來看效果圖
實現思路
- 使用AccessibilityService監聽紅包訊息
- 當有紅包的時候模擬點選
核心程式碼
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: //內容改變時
//獲取根節點
AccessibilityNodeInfo info = getRootInActiveWindow();
mClassName = event.getClassName().toString();
recycle(info, new infoCallBack() { //遍歷根節點
@Override
public void info(final AccessibilityNodeInfo info, String text) {
switch (text) {
case LUCKY_MONEY_OPEN_TEXT1: //準備拆開紅包介面
//查詢到拆開紅包的button,模擬點選
new android.os.Handler().postDelayed(new Runnable() {
@Override
public void run() {
//防封處理,延遲執行
openLuckyMoney(info);
}
},Integer.parseInt
(SpUtil.getString(getBaseContext(),"delay","0")));
break;
case LUCKY_MONEY_RECEIVE_TEXT: //檢測到未拆封紅包:
//模擬點選紅包
info.getParent()
.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
case LUCKY_MONEY_DETAIL_TEXT: //紅包詳情
//模擬點選返回
if (isAppOpen) {
performGlobalAction(GLOBAL_ACTION_BACK);
isAppOpen = false;
}
break;
}
}
});
break;複製程式碼
專案