Overview
Many apps need to recognise a device: to tie a trial or a licence to it, to limit the number of devices per account, or to find a device again after the user has reinstalled the app. KlugDeviceId reads a stable identifier directly from the operating system.
On Android the identifier stays the same after the app is uninstalled and installed again, which makes it a reinstall-proof anchor. On iOS the system identifier is reset when all apps of the same developer are removed; for a reinstall-proof anchor on iOS and macOS use KlugKeychain.
KlugDeviceId is in daily use in our apps, our proof of concept.
Features
- Self-contained: one ANE, no core library or dependency ANEs to add
- One call returns the device identifier on Android and iOS
- Android 8.0 and later: stays the same after uninstalling and reinstalling the app, as long as it is signed with the same key
- No permission needed
- Returns an empty string where no identifier is available, never an error
Supported platforms
On other platforms isSupported returns false, so the same code can stay in a cross-platform app.
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.deviceid</extensionID>
</extensions>
Code examples
Three complete flows. The getters return at once, need no permission and never throw: where no identifier is available they return an empty string. Full documentation →
import com.klug.deviceid.DeviceId; import flash.events.Event; import flash.net.*; // read once at start and keep it: ANDROID_ID on Android, identifierForVendor on iOS var deviceId:String = DeviceId.getInstance().uniqueId; function login( user:String, password:String ):void { var vars:URLVariables = new URLVariables(); vars.user = user; vars.password = password; vars.device = deviceId; // your server binds the licence or the push token to it var req:URLRequest = new URLRequest( "https://your.server/login" ); req.method = URLRequestMethod.POST; req.data = vars; var loader:URLLoader = new URLLoader(); loader.addEventListener( Event.COMPLETE, onLoginResult ); loader.load( req ); }
var dev:DeviceId = DeviceId.getInstance(); // Android: ANDROID_ID stays the same after uninstall and reinstall; only a // factory reset changes it. From Android 8 it is specific to your signing key. var anchor:String = dev.androidId; if ( anchor != "" ) checkTrial( anchor ); // your server: has this device used the trial before? else checkTrialOnIOS(); // iOS: androidId is always "" and identifierForVendor is // reset on uninstall, use KlugKeychain as the anchor there
import flash.utils.setTimeout; function readDeviceId():void { var dev:DeviceId = DeviceId.getInstance(); if ( !dev.isSupported ) { useOwnDesktopId(); // desktop: isSupported is false, every getter returns "" return; } var id:String = dev.uniqueId; if ( id == "" ) setTimeout( readDeviceId, 1000 ); // iOS can briefly have no value: ask again else onDeviceId( id ); }
API overview
| DeviceId.getInstance() | Returns the single instance. |
| isSupported | True on Android and iOS. |
| uniqueId | The device identifier of the running platform: ANDROID_ID on Android, identifierForVendor on iOS; an empty string where not available. |
| androidId | The Android device identifier only, which stays the same after uninstall and reinstall; an empty string on iOS and other platforms. |
Buy KlugDeviceId
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 |