← All extensions

Native extension

KlugDeviceType

com.klug.devicetype

NO APM NEEDED. Download and enjoy. It can’t get any simpler. Just update the Adobe AIR SDK. If you need help, we are here.

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

iOSAndroid In production From €9 / year · Buy

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

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>

Code examples

Three complete flows. The getters return at once and need no permission; every read asks the operating system again. Full documentation →

1 · Choose the layout at start
Layout.as
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();
2 · Your own breakpoints
Grid.as
// 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 );
3 · Follow a foldable when it opens or closes
Resize.as
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.
isSupportedTrue on Android and iOS.
isTabletTrue on a tablet: Android 600 dp or more, iOS iPad; false on other platforms.
isPhoneTrue on a phone; false on other platforms.
deviceType"tablet" or "phone"; an empty string on other platforms.
smallestWidthDpThe 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

Simple
€9 / year
  • Licence for one AIR application
  • All updates for 12 months
  • No support
Buy Simple
Standard
€39 / year
  • Licence for one AIR application
  • All updates for 12 months
  • Answer by e-mail within 7 days
Buy Standard
Priority
€79 / year
  • Licence for one AIR application
  • All updates for 12 months
  • Answer by e-mail within 48 hours
Buy Priority
Taxes are calculated at checkout by Link (Stripe). You enter the application ID of your AIR app during checkout.

Requirements

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