dtmilano / AndroidViewClient

Android ViewServer and ADB client
Apache License 2.0
1.61k stars 344 forks source link

takeSnapshot fails after first time #304

Closed benjoromo closed 2 years ago

benjoromo commented 2 years ago

I create a device and use the device to take a snapshot successfully. The subsequent times I attempt to take a snapshot it fails with the following.

snapshot = self.device.takeSnapshot()

File "/home/uandme/venv/lib/python3.8/site-packages/com/dtmilano/android/adb/adbclient.py", line 850, in takeSnapshot self.send('framebuffer:', checkok=True, reconnect=False) File "/home/uandme/venv/lib/python3.8/site-packages/com/dtmilano/android/adb/adbclient.py", line 311, in send self.checkOk() File "/home/uandme/venv/lib/python3.8/site-packages/com/dtmilano/android/adb/adbclient.py", line 375, in checkOk raise RuntimeError("ERROR: %s %s" % (repr(recv), error)) RuntimeError: ERROR: b'' b''

It appears to work on an old Android version 4.4.4. It fails on Android 7.0 and Android 11. Any thoughts on what is causing this problem?

Thanks, Ben.

dtmilano commented 2 years ago

You need reconnect=True if you are taking multiple screenshots.

dtmilano commented 2 years ago

Or you can use something like https://github.com/dtmilano/AndroidViewClient/blob/master/examples/helper/screenshot.py

benjoromo commented 2 years ago

The reconnect=true worked great on all devices. Thank you for the program and your help.

I am hoping to have a number of android devices all controlled by the same PC. I will take semi regular screenshots, analyze them, and send appropriate mouse clicks and text to control the devices. I have been using AdbClient. Does ViewClient allow sending text and mouse clicks as well? Can I use AdbClient along side ViewClient? What is the most efficient way to do this?

dtmilano commented 2 years ago

Yes you can connect multiple devices, take screenshots and send and get text. ViewClient and AdbClient is one possible combination but there are more, like ViewClient and CulebraTester2-public which is a more powerful backend. Some special cases, for example when you need to take screenshots at a very fast rate, you can even bypass ViewClient and invoke CulebraTester2-public directly.

Don't hesitate to ask any further question here or at stackoverflow#androidviewclient.