In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces AccessibilityService how to achieve Wechat red packet function, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. To configure AccessibilityService, you need to integrate AccessibilityService to perform the operation.
Public class TestAccessibilityService extends AccessibilityService {@ Override public void onAccessibilityEvent (AccessibilityEvent event) {.} @ Override public void onInterrupt () {VirtualControlManager.getInstance () .onCancel ();}}
When using it, you need to configure it in AndroidManifest.xml.
Create a xml folder under the res folder to store the accessibility_service_config.xml
This sentence is very important. I'll use it later. Remember.
Android:accessibilityFlags= "flagDefault | flagRetrieveInteractiveWindows | flagIncludeNotImportantViews"
two。 Start Wechat
Intent intent = new Intent (Intent.ACTION_MAIN); / / intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent// .flag _ ACTIVITY_RESET_TASK_IF_NEEDED); / / add this flag in the session list intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addCategory (Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName ("com.tencent.mm", "com.tencent.mm.ui.LauncherUI"); intent.setComponent (cn) so that Wechat can enter. Context.startActivity (intent)
A lot of code on the Internet to start Wechat in the setFlags parameters are the paragraph I commented, with that section can indeed start Wechat, but can not guarantee that Wechat starts is the most original message list, but Wechat any interface (the user last operation Wechat stay interface), so want to do simulation click operation, to add a lot of judgment interface code and operation, then can I start Wechat must be in the message list The answer is yes, that is, using the following flag, when you start Wechat, you will definitely come to the message list, which saves us the operation.
Intent.FLAG_ACTIVITY_CLEAR_TOP
3. Perform an operation
Through the onAccessibilityEvent (...) method of AccessibilityService, we can get the information of the interface view, use getRootInActiveWindow (), and simulate the operation step by step through the id of view, to the interface of sending red packets.
It should be noted here that when Wechat jumps to the red packet interface, there is a dialog loading animation. When many people jump to the interface of sending red packets, the object obtained through getRootInActiveWindow () is either null or node information is wrong. This is because a dialog is loaded quickly, and some machines can watch the effect of flash. If the phone performance is good, this dialog may not be visible. But the node information is not available when the code is executed.
An attempt has been made to add a delay, but after the delay, the onAccessibilityEvent method is not executed, which is equal to none.
At this point, you need to use the code you talked about at the beginning:
Android:accessibilityFlags= "flagDefault | flagRetrieveInteractiveWindows | flagIncludeNotImportantViews"
After adding this code, we can get the view of the interface of sending red packets through onAccessibilityEvent, and send a code to enter the amount in the interface of sending red packets:
Private void sendLuckMoney () {AccessibilityNodeInfo rootInfo = accessibilityService.getRootInActiveWindow (); if (rootInfo! = null) {List nodeInfoList = rootInfo.findAccessibilityNodeInfosByViewId ("com.tencent.mm:id/clu"); for (AccessibilityNodeInfo nodeInfo: nodeInfoList) {Bundle arguments = new Bundle (); arguments.putCharSequence (AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "10"); nodeInfo.performAction (AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);}
Thank you for reading this article carefully. I hope the article "how to achieve the function of sending red envelopes on Wechat" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.