← All extensions

Native extension

KlugDeviceType

com.klug.devicetype

Reliable phone or tablet detection, asked directly from the operating system, independent of orientation and window size.

iOSAndroid In development

Overview

Many apps show a different layout on a tablet than on a phone. Guessing the device class from the screen size is unreliable: the result can change with orientation, display scaling or the size of the window.

KlugDeviceType asks the operating system itself. On Android it uses the device's smallest screen width in density-independent pixels (600 dp or more is a tablet), the same rule Android uses for its own layouts. On iOS it uses the system's device idiom, which tells an iPad from an iPhone.

The answer is the same in portrait and landscape, at every scaling setting, from the first frame of the app.

Features

  • Phone or tablet, answered by the operating system
  • Stable across orientation, scaling and window size
  • Android: the smallest screen width in dp, for your own thresholds
  • Available at app start, before the first layout
  • No permission needed

Supported platforms

Android arm64 · armv7
iOS arm64

On other platforms isSupported returns false and deviceType is an empty string.

Getting started

Add the extension to your application descriptor:

app.xml
<extensions>
    <extensionID>com.klug.devicetype</extensionID>
</extensions>

Quick example

Layout.as
import com.klug.devicetype.DeviceType;

var type:DeviceType = DeviceType.getInstance();
if ( type.isSupported && type.isTablet )
    useTabletLayout();
else
    usePhoneLayout();

API overview

DeviceType.getInstance()Returns the single instance.
isSupportedTrue on Android and iOS.
isTabletTrue on a tablet.
isPhoneTrue on a phone.
deviceType"tablet" or "phone"; an empty string on other platforms.
smallestWidthDpAndroid: the smallest screen width in dp; -1 where not available.

Requirements

AIR SDK51.x (HARMAN)
iOSiOS 17 or later
AndroidAndroid 6.0 (API 23) or later
PermissionsNone