Teach you to realize Android wechat automatic red envelope grabbing step by step

This paper introduces the implementation method of wechat automatic red envelope grabbing, which mainly realizes the following functions:

1. Automatically open the red envelope on the screen

2. When receiving the red envelope information on the desktop or chat list, automatically enter the chat interface and remove the red envelope

3. Log function to record the detailed log of robbing red envelopes

Implementation principle

1. Use the accessibilityservice auxiliary service to monitor the screen content and realize the purpose of automatically removing red envelopes.

2. Use the activeandroid database to simply record the red packet log

3. Use preference to realize the record of monitoring options

Final interface

Grab red envelope core code

Accessibilityservice configuration

Android: accessibilityeventtypes sets the event type that triggers the listening callback;

Android: packagenames sets the monitoring application. Wechat is monitored here, so fill in the wechat package name com.tencent.mm

Declare in androidmanifest.xml:

Grab red envelope implementation code

Receive the accessibilityevent sent by the system

Detect the node information of listening events

It mainly judges whether there is a new red envelope by detecting key text information such as "receiving red envelope"

When receiving the red envelope, judge whether to "Android. Widget. LinearLayout" to shield the text interference in the chat message

When removing the red envelope, because the wechat version may be different, two judgments are made at the same time to be compatible with some versions

After the red envelope is removed, it needs to be returned automatically. There are the following situations: it is grabbed, the hand is slow, and the red envelope is a red envelope issued by itself

The following is the code for listening to the chat list:

The following is the code for listening to notification information:

Acquisition of red envelope information and storage of logs

By obtaining the sub information of the node, the information such as the red envelope sender, the amount and the time of red envelope grabbing are obtained respectively, and a simple form is established to record the information respectively.

Storage operation:

summary

The main code has basically ended here. At present, it is tested OK on the latest version of wechat, and there are still the following problems:

1. The same person's continuous messages cannot be automatically robbed, because in order to prevent repeated clicks, the same person's red envelope will not be clicked again after being robbed

2. Accessibilityservice is sometimes turned off by the system after it has been turned on for a long time

Conclusion

The above is the whole content of this article. I hope it can be helpful to your study and work.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>