NadavRub
NadavRub

Reputation: 2610

Android, ADB CommandLine tool get ORientation

Environment

Android SmartPhone USB connected to a Windows Desktop

Use-case

Implement an ADB command-line tool to programatically (c++) get the current orientation

Problem to resolve

If I would have implemented a NativeActivity I would have used "AConfiguration_fromAssetManager" followed by "AConfiguration_getOrientation".

Given that I am implementing an ADB cmdline tool and not an activity, how should I have this implemented?, Can I still use "AConfiguration_fromAssetManager"? Does an asset manager exist for a cmdline tool? how do I get access to it?

Any other way to get the current orientation using a C++ ADB cmdline tool ?

Upvotes: 1

Views: 2594

Answers (1)

Jared Rummler
Jared Rummler

Reputation: 38121

Running this from the command-line worked for me:

adb shell "dumpsys input | grep SurfaceOrientation | awk '{print $2}' | head -n 1"

If it returns 0 or 2 the device is in portrait. If it returns 1 or 3 the device is in landscape.

Note: I am on a rooted device and have busybox with grep, awk, and head applets. You may need to parse the output of dumpsys elsewhere.

Source: Check if device is landscape via ADB

Upvotes: 2

Related Questions