Saturday, 15 April 2017

how to get screenshot of Android using adbkit

I am using Node js to get the image which is displayed on the Android phone screen.

Using adbkit, I was able to get the ID of the device and establish connection (the phone is usb connected to the computer - windows)

Here is the function that ought to get the image:

function get_screen (device_id) {
   client.framebuffer(device_id, 'jpeg', function(data) {
     var png_name = 'png_name_101.jpeg'
     var stream = fs.createWriteStream(png_name)
     data.pipe(stream)
   })
 }

Also, I am calling it from:

/*
 * @device_id: The serial number of the device.
 *      Corresponds to the device ID in client.listDevices()
 */
 exports.connect_device = function(device_id) {
   client.tcpip(device_id)
        .then(function(port) {
          return client.waitForDevice(device_id).return(port)
        })
        .then(function(port) {
          return client.getDHCPIpAddress(device_id)
            .then(function(ip) {
              return client.connect(ip, port)
            })
            .then(function(id) {
              return client.waitForDevice(id)
            })
            .then(function(id) {
              return client.forward(id, 'tcp:9222',
                        'localabstract:chrome_devtools_remote')
            })
          })
   get_screen(device_id) // <--- here
 }

The function succeeds in creating the jpeg file, however, its size is 0KB! not what I expected (expected to see a screen-shot!)

P.S. no exception is thrown. GraphicMagick is installed, and the adb daemon is up and running.

How can I get the actual screen in that jpeg file?



via ThunderWiring

No comments:

Post a Comment