Pyqt adb gets the Android mobile phone screen and pyqtandroid
AdbAndroid Debug Bridge serves as the debugging Bridge. Adb works in a special way. It listens to Socket TCP 5554 and other ports to allow the IDE to communicate with Qemu. By default, adb uses the network port related to daemon, we can manage the status of the device or mobile phone simulator. You can also perform many mobile phone operations, such as installing software, upgrading the system, and running shell commands. In short, adb is a bridge between Android phones and PCs, allowing users to perform comprehensive operations on their mobile phones on their computers.
Adb:
Http://files.cnblogs.com/files/dcb3688/adb.7z
Adb command:
Category |
Command |
Description |
Comments |
Options |
-d |
Manage abd only through USB interface. |
An error is returned if it is not just managed using a USB interface. |
-e |
The adb is managed only through the simulator instance. |
If it is not just managed by the simulator instance, an error is returned. |
-s <serialNumber> |
Use the allowed command numbers of the simulator/device to send commands to manage the adb (for example, "emulator-5556 "). |
If no number is specified, an error is returned. |
General |
devices |
View the list of all devices connected to simulators/devices. |
View Querying for Emulator/Device Instances for more information. |
help |
View All commands supported by adb .. |
|
version |
View the version serial number of adb. |
|
Debug |
logcat [<option>] [<filter-specs>] |
Output log data to the screen. |
|
bugreport |
View the bug report, as shown in figuredumpsys ,dumpstate , Andlogcat Information. |
|
jdwp |
View the available JDWP information of the specified facility. |
Availableforward jdwp:<pid> Port ing information to connect to the specified JDWP process. For example:
adb forward tcp:8000 jdwp:472
jdb -attach localhost:8000 |
Data |
install <path-to-apk> |
Install Android as (you can specify the complete path for the simulator/idea data file .apk ). |
|
pull <remote> <local> |
Copy the specified file from the simulator/facility to the computer. |
|
push <local> <remote> |
Copy the specified file from the computer to the simulator/device. |
|
Ports and Networking |
forward <local> <remote> |
Remotely connect to the simulator/facility through the socket method using the locally specified port |
The following information is required:
tcp:<portnum>
local:<UNIX domain socket name>
dev:<character device name>
jdwp:<pid>
|
ppp <tty> [parm]... |
Run ppp through USB:
<tty> -The tty for PPP stream. For exampledev:/dev/omap_csmi_ttyl .
[parm]... & Mdash zero or more PPP/PPPD options, suchdefaultroute ,local ,notty , Etc.
You must be reminded that you cannot automatically start the PDP connection. |
|
Scripting |
get-serialno |
View the serial number of the adb instance. |
View Querying for Emulator/Device Instances for more information. |
get-state |
View the current status of the simulator/facility. |
wait-for-device |
If the device is offline, it will not be executed, that is, the instance status isdevice . |
You can reprint the command in the adb command in advance. The command in the command is not executed before the simulator/device is connected. The example is as follows:adb wait-for-device shell getprop Note that these commands do not start adb before all systems start up. Therefore, you cannot execute other commands before all systems start up. For example: Useinstall Android packages are required only when the system is fully started. For example:adb wait-for-device install <app>.apk The preceding command is executed only when the simulator/device is connected to the adb service, and an error occurs before the Android system is fully started. |
Server |
start-server |
Select whether the service starts the adb service process. |
|
kill-server |
Terminate the adb service process. |
|
Shell |
shell |
Use remote shell commands to Control Simulators/device instances. |
View more information for more information. |
shell [<shellCommand>] |
Connect to the simulator/facility and execute shell commands. After the command is executed, exit the remote shell terminal.
|
Use adb shell screencap-p to obtain the mobile phone screen
The Code is as follows:
#-*-Coding: UTF8-*-from PyQt4.QtGui import * import sys, OS, timefrom PyQt4.QtCore import * class myadb (QDialog): def _ init _ (self ): super (myadb, self ). _ init _ () self. xsize = 480 self. ysize = 850 self. resize (self. xsize, self. ysize) self. setWindowFlags (Qt. dialog | Qt. customizeWindowHint) self. theading = MyTheading () self. connect (self. theading, SIGNAL ("updatescreen"), self. update) self. theading. start () # thread start def paintEvent (self, event): painter = QPainter () painter. begin (self) painter. setRenderHint (QPainter. antialiasing) painter. drawPixmap (0, 0, self. xsize, self. ysize, QPixmap ("C: \ screen.png") painter. end () class MyTheading (QThread): def _ init _ (self): super (MyTheading, self ). _ init _ () def run (self): while True: command = 'adb shell screencap-p/sdcard/screen.png 'OS. system (command) cmdpic = "adb pull/sdcard/screen.png C: \ screen.png" OS. system (cmdpic) self. emit (SIGNAL ("updatescreen") if _ name _ = '_ main _': app = QApplication (sys. argv) appadb = myadb () appadb. show () app.exit(appadb.exe c _())
Running error:
adb server is out of date. killing....
The reason is that the ADB server is not started successfully and its port is occupied.
First, find the corresponding Port:
adb nodaemon server
Cannot bind 'tcp: 8080'
Continue to find out which process occupies the port
netstat -ano | findstr "5037"
After finding the information, the corresponding process will be killed (my computer is occupied by tadb.exe) and then the script will be executed
Effect: