Do you know what you can do with python scripts to control Android phones?

image

 

Sometimes I want to write scripts for Android, but it is too troublesome to write image processing in java or kotlin, and I don't bother to learn the scripts of the button wizard. adb is ok, but it is a little inconvenient to use a computer in many cases. I feel that cloud phones are more convenient now. For example: Red Finger and Aiyuntu. I prefer to use cloud phones to hang up and hang up. You can check the on-hook progress on the phone at any time.

So I wrote a basic Android receiver to receive the control commands of the server-side python to control the Android machine.

Many people learn python and after mastering the basic grammar, they don't know where to find cases to get started.

Many people who have done case studies do not know how to learn more advanced knowledge.

So for these three types of people, I will provide you with a good learning platform, free to receive video tutorials, e-books, and the source code of the course!

QQ group: 701698587

 

https://github.com/nladuo/PyAndroidControl

 

Architectural ideas

The architecture is relatively simple, with an Android side and a webserver side.

image

 

In fact, the app uploads screenshots to the web terminal every once in a while, and then you can use python to do a wave of image search or other things at will, and then return the command to the app terminal, and then the app executes the corresponding command.

 

Instructions

1. Install PyAndroidControl APP

Because you want to control the device, you need to grant root permission to the PyAndroidControl application here.

https://github.com/nladuo/PyAndroidControl/releases

2. Modify the code according to personal needs

Here I provide a get_commands method for developers to use. There are two parameters. The first token represents the label when logging in to distinguish users. The second img_file represents the screenshot of the Android device.

So just modify the simple-control-server/logics.py file.

def get_commands(token, img_file):
    """ analyze the screenshot and send
    commands back to android device """
    img_file.save("tmp.png")
    print(token)
    # your adb shell commands
    cmds = [
    'input text "111"',
    'input text "222"',
    'input text "333"',
    ]
    return cmds

For the sake of simplicity, an example of automatically inputting "111", "222", and "333" every second is provided.

Guess you like

Origin blog.csdn.net/Python_kele/article/details/115147415