Navigate back to the homepage

Magically turn your phone into a tablet with adb for testing tablet views!

Matt McKenna
March 28th, 2020 · 3 min read

The Pledge

So you forgot your tablet at the office and now you are working from home for the foreseeable future. It’s still important to test those tablet views! Here’s a quick and painless way to turn an ordinary phone into a tablet and back again. This isn’t one of those one way disappearing acts!

Tools of the Trick

  1. Android Debug Bridge - Our good friend the Android Debug Bridge (adb). We will be using some commands here to perform our magic trick.
  2. Search Engine - One of your choice, I recommend DuckDuckGo (go privacy!)
  3. Phone - Can be any phone you want to use. I promise we will put it back to the way it was by the end of this article
  4. scrcpy - An application to view and control your Android device from your computer

The Turn

The first step you want to take is to find the resolution and pixel density of the tablet you want to emulate on your device. For example, if we want to emulate a Pixel C device we can search up its specs on a site like GSMArena. We find that this device has a 2560x1800 resolution display with a pixel density of 308 ppi (pixels per inch).

GSM Arena website Pixel C Specs

For the next step I’m going to assume that adb is installed and set up on your system. If it is not, check out this write up from xda developers.

The Android Debug Bridge has a slew of great commands. The one we will be using today is the shell command with the wm command.

shell - allows us to access the linux shell on an Android device

wm - accesses the devices window manager

We also need to know two parameters for the wm command.

size - which will allow us to see our current and original screen resolution, as well as set a desired screen resolution

density - which allows us to see our current and original pixel densities as well as set a desired pixel density. Lets try this out in our terminal.

Now let’s try this command! Make sure you have your device connected and USB Debugging enabled! I am running this on a Google Pixel 4XL. Here’s what is shown when running these commands

1> adb shell wm size
2Physical size: 1440x3040
3
4> adb shell wm density
5Physical density: 560

As you can see we are given the original resolution with size and the original pixel density with density.

Pixel 4XL Original Screen resolution and density

Time to become a tablet! Remember this is easily reversible if something goes awry. Let’s grab the resolution of a Pixel C tablet and set our phone resolution to it using the command:

1> adb shell wm size 2560x1800

You should see your device make this change immediately.

Pixel 4XL Screen resolution after change to 2560x1800

Running the size command again will show that we now have another line of output for the Override size.

1> adb shell wm size
2Physical size: 1440x3040
3Override size: 2560x1800

Now the screen will look a little funny but this is because the pixel density of the device most likely isn’t calibrated correctly for this resolution. Lets see what it looks like when we change only the density.

1> adb shell wm density 308
Pixel 4XL Screen density after change to 308ppi

And again our change can be verified by running the density command once more.

1> adb shell wm density
2Physical density: 560
3Override density: 308

Now it’s time to bring it all together changing both size and density to match what the Pixel C specs have!

1> adb shell wm size 2560x1800
2> adb shell wm density 308

Alakazam!

Pixel 4XL Screen resolution after change of size to 2560x1800 and density to 308ppi

A tablet! This is similar to changing the resolution or scaling on your laptop or monitor! Now when you run your app the tablet specific views will be rendered!

Hmm, it still looks funny on the device though. It’s probably pretty small. It might not even respond to touch inputs. That’s okay! This is expected. There are a few ways we can address this. Firstly, a Pixel C is a tablet device with a very high resolution screen and pixel density. Choosing a resolution and pixel density from a tablet that isn’t quite as large as the Pixel C’s will provide a bit of a better experience. However, there is a cooler option.

Introducing scrcpy

If you have never used scrcpy before you will love it. It’s a magic trick all in its own by some developers at Genymobile to control and view your Android devices from your computer. It can easily be installed for all platforms following the instructions on their Github README. Now that it’s installed all we need to do is open up a terminal and run:

1> scrcpy

If you only have one device connected you will be able to see it right away! If you have more than one you will need to get your device’s serial number and then use that to invoke scrcpy.

1> adb devices
2List of devices attached
30123456789abcdef device
4
5> scrcpy -s 0123456789abcdef
Pixel 4XL Rendering slack as a tablet via scrcpy on a mac desktop

The reason we are using scrcpy here is the window is resizable so you can now enjoy that full size “tablet experience” being rendered on your phone and use your mouse and keyboard for inputs! And voila! We now have a solution for seamless tablet development.

The Prestige

When done working on tablet views it is very easy to undo our tablet transformation trick! All that is needed is a simple reset with:

1> adb shell wm size reset
2> adb shell wm density reset

Boom! Back in the phone business. But wait! We can go even further. We can look up the screen settings of some smaller phones to see how our views look on smaller screens. I’ll leave this to you to try on your own! I hope this has helped you if you need to check things out on a tablet but happen to find yourself without one!

Lastly, please remember to stay home if you can and wash your hands. I wish for you to be happy and healthy in this time of viruses and social distancing. If you have any questions about this article or just need some human interaction please reach out on Twitter on @StoicallyTyped or @himattm!


Thanks to unsplash-logoRodion Kutsaev for the hero image!

Hey! We've got a newsletter!

Your weekly dose of bite sized Android news and events delivered Monday mornings to kick off your week.

Each issue contains TL;DRs of recent articles, a developer tool highlight, interview practice, and a stoic sentiment applied to tech careers.

All with a No-Spam Guarantee.

Read more about it here!

More articles from StoicallyTyped

Android Emulators vs Bluetooth Headphones

How to Fix Poor Audio Quality When Using Android Emulators

December 17th, 2021 · 2 min read

Learning Live Templates for Jetpack Compose

What are Live Templates? How can they speed up your development? And how to create your own for Jetpack Compose!

April 20th, 2021 · 6 min read
© 2020–2021 StoicallyTyped
Link to $https://twitter.com/himattmLink to $https://github.com/himattmLink to $https://instagram.com/himattmLink to $https://unsplash.com/@mmckennaLink to $https://medium.com/@himattm