Android中微信抢红包插件原理解析及开发思路

2019-12-10 19:08:02刘景俊

第二种:我们在onAccessibilityEvent事件监听的方法中做包名的过滤(这种方式最常用)

@Override 
public void onAccessibilityEvent(AccessibilityEvent event) { 
String pkgName = event.getPackageName().toString(); 
if("xxx.xxx.xxx".equals(pkgName)){ 
}else if("yyy.yyy.yyy".equals(pkgName)){ 
}else if("....".equals(pkgName)){ 
} 
}

第三步、在onAccessibilityEvent方法中监听指定的事件

比如我们需要监听有通知栏消息的事件:

@Override 
public void onAccessibilityEvent(AccessibilityEvent event) { 
int eventType = event.getEventType(); 
switch (eventType) { 
case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: 
//....... 
} 
}

这个事件类型很多的,我们可以查看AccessibilityEvent类的源码:

@Deprecated 
public static final int MAX_TEXT_LENGTH = 500; 
/** 
* Represents the event of clicking on a {@link android.view.View} like 
* {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc. 
*/ 
public static final int TYPE_VIEW_CLICKED = 0x00000001; 
/** 
* Represents the event of long clicking on a {@link android.view.View} like 
* {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc. 
*/ 
public static final int TYPE_VIEW_LONG_CLICKED = 0x00000002; 
/** 
* Represents the event of selecting an item usually in the context of an 
* {@link android.widget.AdapterView}. 
*/ 
public static final int TYPE_VIEW_SELECTED = 0x00000004; 
/** 
* Represents the event of setting input focus of a {@link android.view.View}. 
*/ 
public static final int TYPE_VIEW_FOCUSED = 0x00000008; 
/** 
* Represents the event of changing the text of an {@link android.widget.EditText}. 
*/ 
public static final int TYPE_VIEW_TEXT_CHANGED = 0x00000010; 

/** 
* Represents the event of opening a {@link android.widget.PopupWindow}, 
* {@link android.view.Menu}, {@link android.app.Dialog}, etc. 
*/ 
public static final int TYPE_WINDOW_STATE_CHANGED = 0x00000020; 
/** 
* Represents the event showing a {@link android.app.Notification}. 
*/ 
public static final int TYPE_NOTIFICATION_STATE_CHANGED = 0x00000040; 

/** 
* Represents the event of a hover enter over a {@link android.view.View}. 
*/ 
public static final int TYPE_VIEW_HOVER_ENTER = 0x00000080; 
/** 
* Represents the event of a hover exit over a {@link android.view.View}. 
*/ 
public static final int TYPE_VIEW_HOVER_EXIT = 0x00000100; 
/** 
* Represents the event of starting a touch exploration gesture. 
*/ 
public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 0x00000200; 

/** 
* Represents the event of ending a touch exploration gesture. 
*/ 
public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400; 
/** 
* Represents the event of changing the content of a window and more 
* specifically the sub-tree rooted at the event's source. 
*/ 
public static final int TYPE_WINDOW_CONTENT_CHANGED = 0x00000800; 

/** 
* Represents the event of scrolling a view. 
*/ 
public static final int TYPE_VIEW_SCROLLED = 0x00001000; 
/** 
* Represents the event of changing the selection in an {@link android.widget.EditText}. 
*/ 
public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 0x00002000; 

/** 
* Represents the event of an application making an announcement. 
*/ 
public static final int TYPE_ANNOUNCEMENT = 0x00004000; 

/** 
* Represents the event of gaining accessibility focus. 
*/ 
public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 0x00008000; 
/** 
* Represents the event of clearing accessibility focus. 
*/ 
public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 0x00010000; 

/** 
* Represents the event of traversing the text of a view at a given movement granularity. 
*/ 
public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY = 0x00020000; 
/** 
* Represents the event of beginning gesture detection. 
*/ 
public static final int TYPE_GESTURE_DETECTION_START = 0x00040000; 
/** 
* Represents the event of ending gesture detection. 
*/ 
public static final int TYPE_GESTURE_DETECTION_END = 0x00080000; 
/** 
* Represents the event of the user starting to touch the screen. 
*/ 
public static final int TYPE_TOUCH_INTERACTION_START = 0x00100000; 
/** 
* Represents the event of the user ending to touch the screen. 
*/ 
public static final int TYPE_TOUCH_INTERACTION_END = 0x00200000; 
/** 
* Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: 
* The type of change is not defined. 
*/ 
public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0x00000000; 

/** 
* Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: 
* A node in the subtree rooted at the source node was added or removed. 
*/ 
public static final int CONTENT_CHANGE_TYPE_SUBTREE = 0x00000001; 

/** 
* Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: 
* The node's text changed. 
*/ 
public static final int CONTENT_CHANGE_TYPE_TEXT = 0x00000002; 
/** 
* Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: 
* The node's content description changed. 
*/ 
public static final int CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 0x00000004;