preface

After reading it, you can also write a firework and set off an eco-friendly firework for your family or girlfriend or boyfriend. Yeah, it’s very romantic. If you don’t have a girlfriend, show it to your family! No boyfriend. I can help you with that.

Let’s see what it looks like

Does it look like a manual. Haha, but if you send 100 messages all the time, it’s different.

Download address

You need to go to Github to download the assistant APK address

Qing Yu Case · Yuan Xi

Song Xin Qiji

Dongfeng night put thousands of trees, more blowing, stars like rain. BMW carvings filled the road with fragrance.

Feng flute sound, jade pot light turn, a night fish dragon dance.

Moths snow willow gold wisp, laughter yingying dark fragrance.

Find him thousands of baidu, suddenly look back, that person is in, the lights dim.

Among them, dongfeng night flowers thousand trees, more blown, stars like rain. It’s about fireworks.

I’m sure a lot of people don’t really care how it’s done, because I don’t either.

Enter the main interface to open the barrier-free service. Different brands may open different pages. Notice that the service of setting off fireworks is good to open.

App interface

The unit in seconds is the interval between sending fireworks

Number of fireworks this is the number of fireworks that were sent

To turn on the fireworks

After successful startup

After successful startup

The use method is in the input box input started fireworks, you can start to send fireworks, because the monitoring input box, may not be too timely, more than two tries. Have a question or comment below.

nagging

Had to write early, for a variety of reasons did not write, ask is lazy. Of course, there is also a reason that I have not been able to get the chat records of wechat. Those chats are just a view without text. In wechat 8.0, wrote a fireworks auxiliary, of course, also put a bomb. I’m not going to start with the intro, because I’m not good at writing intro articles, okay! I was lazy in the end.

AccessibilityService

AccessibilityService is designed to help disabled users with Android devices and applications run in the background and listen for user interface transitions such as page transitions, focus changes, notifications, Toast, etc. The system receives a callback when AccessibilityEvents is triggered. Later, it was developed by developers in another way and used in the development of some plug-ins, such as automatic chat assistant and wechat red envelope assistant, which I believe many people have used. Xiaomi opened the source red envelope assistant and pushed the AccessibilityService to a climax.

Let’s start

At first, I wanted to get the wechat chat record to touch the fireworks, but I couldn’t get the wechat chat record all the time. I had to settle for something else. Think again,think again,think again,think again. Think of listening to input boxes as a command.

The android tools uiautomatorviewer

This tool is used to get the page layout data, the tool is in your androidSdk\SDK\tools\bin (depending on your installation directory)

The first step is to listen for the trigger command

Listen to the input box, the input box text as a command. The code is quite simple, not what level, but also very urgent. So we’ll see. The main steps here are

1, find the input box node, this search input box node below said.

2, listen to the input box.

3. The message goes out.

4, trigger fireworks send.

5. Reset the data.

    private fun listenerInputCmd(a) {

        if (isStart) returnval editText = findInput() ? :return

        if (editText.text.isNullOrEmpty()) return

        if ("Let the fireworks go!"! = editText.text.toString()) { Log.d(TAG,"AccessibilityEvent editText1:" + editText.text)
            return
        }
        // Find the send buttonval sendBtn = findSendButton() ? :return
        // Send the message and get started!
        val isSuccess = sendBtn.performAction(AccessibilityNodeInfo.ACTION_CLICK)
        if(! isSuccess)return
        
        reSet()
        
        isStart = true
    }

Copy the code

We use the tool UIAutomatorViewer to analyze the node of the input box. As shown in the figure, we know that the input box node is com.tencent. Mm :id/auj, so we can start to write code.

    /** * Find the input box */
    private fun findInput(a): AccessibilityNodeInfo? {
        // Find the node
        val input = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/auj")
        if (input.isNullOrEmpty()) {
            return null
        }
        if (input[input.size - 1].className ! ="android.widget.EditText") {
            return null
        }
        return input[input.size - 1]}Copy the code

Set the fireworks to the input box, and then press the send button.

Fireworks set to the input box

Let me see how it works. This support is also a lot of API play. Call AccessibilityNodeInfo’s performAction directly to set the content.

 val arguments = Bundle()
 arguments.putCharSequence(
 AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "[celebrate]" )
 val editText = findInput()
 // Enter fireworks in the input box
 editText.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)

Copy the code

Press the send button

The first step is to look for the button and find the node that sent the button. As shown in the figure:

Then we know that the node ID of the button is com.0ce.mm: ID /ay5, so we can play with it. Or use findAccessibilityNodeInfosByViewId accurate locating node. Similar to the above, I believe the smart you see a understand. You can talk to me privately if you don’t know.

    private fun findSendButton(a): AccessibilityNodeInfo? {
        // The node of the message send button.
        val sendButton =
            rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/ay5")
        if (sendButton.isNullOrEmpty()) {
            return null
        }
        sendButton.forEach {
            / / to match the button
            if (it.className == "android.widget.Button") {
                Log.d(TAG, "found send button!")
                return it
            }
        }
        return null

    }


Copy the code

After all the hard work, it’s time to get into the fireworks theme

In fact, this is relatively simple, here to ignore the judgment of the details, from the big aspect, we walk in several steps.

1, send sleep time, send too frequently, is sent to fail, because the server can not bear. It is recommended to sleep for 0.8 seconds.

2. Click the send button

3. Find the input box and set the fireworks.

4. When sending fireworks reaches the maximum number of times, the sending ends and the parameters are reset.


   // Enter the loop
        while (count < maxSendMessageCount) {
            if(! isStart)returnThread.sleep(sleepTime.toLong()) val isSuccess = sendBtn? .performAction(AccessibilityNodeInfo.ACTION_CLICK) Log.d(TAG,"startFireworks: //ing$count--- $isSuccess")

            if (isSuccess!!) {
                count++
            }
            val arguments = Bundle()
            // Enter fireworks in the input box
            arguments.putCharSequence(
                AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
                "[celebrate]"
            )
            val editText = findInput()

            if (editText == null) {
                runningType = 0
                return
            }
            editText.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)
        }
        // Reset the parameters
        reSet()

Copy the code

Of course, there are some details in the code that are not mentioned here, but you can look at the code yourself, such as the number of times to send the judgment, or to prevent multiple times in the judgment.

Apk Download address

You need to go to Github to download it

Assistant APK address

Full code address

The code address

conclusion

Originally wanted to write red envelope assistant, ha ha, due to time (actually is I can not write out), became a fireworks assistant. Train of thought is changeable, draw inferential lessons from one example, still can become friend circle point sponsor hand.

My knowledge is limited, if there is a description of the error, I hope the tiger is right.

Look at thisLike you owe me a thumbs up.

Thank you very much. I wish everyone a happy New Year, if happiness is not easy, then I wish you peace. Your praise is like the warm sun in winter, warming my heart.

On this special day, I send haizi’s poem to you:

Stranger, I also bless for you

May you have a bright future

May all shall be well, Jack shall have Jill

May you find happiness in this earthly world