下面是监听聊天列表的代码:
- private boolean watchList(AccessibilityEvent event) {
- // Not a message
- if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED || event.getSource() == null)
- return false;
-
- List<AccessibilityNodeInfo> nodes = event.getSource().findAccessibilityNodeInfosByText(RED_PACKET_NOTIFICATION);
- if (!nodes.isEmpty()) {
- AccessibilityNodeInfo nodeToClick = nodes.get(0);
- CharSequence contentDescription = nodeToClick.getContentDescription();
- if (contentDescription != null && !lastContentDescription.equals(contentDescription)) {
- nodeToClick.performAction(AccessibilityNodeInfo.ACTION_CLICK);
- lastContentDescription = contentDescription.toString();
- return true;
- }
- }
- return false;
- }
下面是监听通知信息的代码:
- private boolean watchNotifications(AccessibilityEvent event) {
- // Not a notification
- if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
- return false;
-
- // Not a hongbao
- String tip = event.getText().toString();
- if (!tip.contains(RED_PACKET_NOTIFICATION)) return true;
-
- Parcelable parcelable = event.getParcelableData();
- if (parcelable instanceof Notification) {
- Notification notification = (Notification) parcelable;
- try {
- notification.contentIntent.send();
- } catch (PendingIntent.CanceledException e) {
- e.printStackTrace();
- }
- }
- return true;
- }
红包信息的获取,及日志的存储: (编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|