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
On other platforms isSupported returns false and deviceType is an empty string.
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.devicetype</extensionID>
</extensions>
Quick example
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. |
| isSupported | True on Android and iOS. |
| isTablet | True on a tablet. |
| isPhone | True on a phone. |
| deviceType | "tablet" or "phone"; an empty string on other platforms. |
| smallestWidthDp | Android: the smallest screen width in dp; -1 where not available. |
Requirements
| AIR SDK | 51.x (HARMAN) |
| iOS | iOS 17 or later |
| Android | Android 6.0 (API 23) or later |
| Permissions | None |