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, independent of how your app scales its content, from the first frame of the app.
Features
- Self-contained: one ANE, no core library or dependency ANEs to add
- Phone or tablet, answered by the operating system
- Stable across orientation and app scaling
- The smallest screen width in dp (points on iOS), 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>
Code examples
Three complete flows. The getters return at once and need no permission; every read asks the operating system again. Full documentation →
import com.klug.devicetype.DeviceType; var type:DeviceType = DeviceType.getInstance(); // the same answer in portrait and landscape, available before the first layout if ( !type.isSupported ) useDesktopLayout(); // other platforms: deviceType is "" else if ( type.isTablet ) useTabletLayout(); // Android: 600 dp or more · iOS: iPad else usePhoneLayout();
// dp on Android, points on iOS; -1 where not available var sw:int = type.smallestWidthDp; var columns:int; if ( sw >= 720 ) columns = 3; // large tablet else if ( sw >= 600 ) columns = 2; // small tablet else columns = 1; // phone, or -1: not available buildGrid( columns );
import flash.events.Event; var current:String = type.deviceType; // every read asks the system again, nothing is cached stage.addEventListener( Event.RESIZE, function( e:Event ):void { var now:String = type.deviceType; if ( now == current ) return; // a rotation alone never changes it current = now; rebuildLayout( now ); // Android: opening a foldable can turn "phone" into "tablet" }); // iOS: isTablet follows the device (iPad) and does not change; // smallestWidthDp follows the screen the app is shown on
API overview
| DeviceType.getInstance() | Returns the single instance. |
| isSupported | True on Android and iOS. |
| isTablet | True on a tablet: Android 600 dp or more, iOS iPad; false on other platforms. |
| isPhone | True on a phone; false on other platforms. |
| deviceType | "tablet" or "phone"; an empty string on other platforms. |
| smallestWidthDp | The smaller screen dimension: dp on Android, points on iOS; -1 where not available. |
Buy KlugDeviceType
A yearly licence for one AIR application, with all updates for 12 months. After payment you receive the extension, the ActionScript library and the documentation by e-mail, usually within one business day. Licence and terms
- Licence for one AIR application
- All updates for 12 months
- Answer by e-mail within 7 days
- Licence for one AIR application
- All updates for 12 months
- Answer by e-mail within 48 hours
Requirements
| AIR SDK | 51.x (HARMAN) |
| iOS | iOS 17 or later |
| Android | Android 6.0 (API 23) or later |
| Permissions | None |