Getting Device Properties like OS, Model, Brand, SDK Version and CPU on AIR for Andoid
Ever since the pre-release beta of AIR for Android, I’ve been kind of frustrated that there was no API for getting out very specific device information. I would like to get information like brand, model, OS version and CPU, LCD Density etc. You get the idea. So I went on my own quest. (If Adobe is not doing it, i have to it myself right?
)
After searching on loads of Android forums, the SDK and OS documentation, I finally found what i was looking for!
Turns out that every Android device has a properties file kind of like ANT uses for building. This file is used for customizations by vendors, so everyone can make their own flavor. (This build.prop file is created by build.sh if you’d like know) This file is just string data so very easy to parse and use for your use. Right now I use this primarily for my own analytics.
So what did i do? I created a little parser that reads in this file straight from the file system and maps certain values to a class variable to save them.
Below is the complete GitHub project to get you started and as an added bonus I’ve added two props files from different types of phones, a HTC Hero and HTC Desire. (These prop files do not contain any sensitive personal information, only device specific properties).
This project is also on my project page and also hosted on GitHub.
Here is the code to make it all work (The class files are also commented):
var deviceInfo : NativeDeviceInfo = new NativeDeviceInfo();
deviceInfo.addEventListener(NativeDeviceInfoEvent.PROPERTIES_PARSED, handleDevicePropertiesParsed);
deviceInfo.debug = false;
deviceInfo.parse();
private function handleDevicePropertiesParsed(event : NativeDeviceInfoEvent) : void {
NativeDeviceInfo(event.target).removeEventListener(NativeDeviceInfoEvent.PROPERTIES_PARSED, handleDevicePropertiesParsed);
trace(PropertyVO(NativeDeviceProperties.OS_NAME).label + " - " + PropertyVO(NativeDeviceProperties.OS_NAME).value);
trace(PropertyVO(NativeDeviceProperties.OS_VERSION).label + " - " + PropertyVO(NativeDeviceProperties.OS_VERSION).value);
trace(PropertyVO(NativeDeviceProperties.OS_BUILD).label + " - " + PropertyVO(NativeDeviceProperties.OS_BUILD).value);
trace(PropertyVO(NativeDeviceProperties.OS_SDK_VERSION).label + " - " + PropertyVO(NativeDeviceProperties.OS_SDK_VERSION).value);
trace(PropertyVO(NativeDeviceProperties.OS_SDK_DESCRIPTION).label + " - " + PropertyVO(NativeDeviceProperties.OS_SDK_DESCRIPTION).value);
trace(PropertyVO(NativeDeviceProperties.PRODUCT_MODEL).label + " - " + PropertyVO(NativeDeviceProperties.PRODUCT_MODEL).value);
trace(PropertyVO(NativeDeviceProperties.PRODUCT_BRAND).label + " - " + PropertyVO(NativeDeviceProperties.PRODUCT_BRAND).value);
trace(PropertyVO(NativeDeviceProperties.PRODUCT_NAME).label + " - " + PropertyVO(NativeDeviceProperties.PRODUCT_NAME).value);
trace(PropertyVO(NativeDeviceProperties.PRODUCT_VERSION).label + " - " + PropertyVO(NativeDeviceProperties.PRODUCT_VERSION).value);
trace(PropertyVO(NativeDeviceProperties.PRODUCT_BOARD).label + " - " + PropertyVO(NativeDeviceProperties.PRODUCT_BOARD).value);
trace(PropertyVO(NativeDeviceProperties.PRODUCT_CPU).label + " - " + PropertyVO(NativeDeviceProperties.PRODUCT_CPU).value);
trace(PropertyVO(NativeDeviceProperties.PRODUCT_MANUFACTURER).label + " - " + PropertyVO(NativeDeviceProperties.PRODUCT_MANUFACTURER).value);
trace(PropertyVO(NativeDeviceProperties.OPENGLES_VERSION).label + " - " + PropertyVO(NativeDeviceProperties.OPENGLES_VERSION).value);
trace(PropertyVO(NativeDeviceProperties.LCD_DENSITY).label + " - " + PropertyVO(NativeDeviceProperties.LCD_DENSITY).value);
trace(PropertyVO(NativeDeviceProperties.DALVIK_HEAPSIZE).label + " - " + PropertyVO(NativeDeviceProperties.DALVIK_HEAPSIZE).value);
}
You can find the this project on GitHub, download with all the class files + two different build.prop files.
You can also download the demo app from the Android Market:
Tell me what you think and for what you could use this extracted information for, love to hear from you!
Enjoy!






DTO is the new VO
http://en.wikipedia.org/wiki/Data_Transfer_Object
Hi Jankees, i updated my post so now it reads DTO
So anyway to get the UDID from a similar file of the phone?
How about the actual phone number, language, region/country?
S C O R E!
I thought this wasn’t possible! Been banging my head around for this:
http://blog.zarate.tv/2011/03/20/find-manufacturer-and-device-model-from-air/
Awesome, thanks for sharing!
Hi again Sidney. Downloaded and took a look to the code, very neat and simple to follow. Even so, I’ve forked and the sent you a pull request in github. The changes I’ve made are only to make the usage even simpler.
Would be great if you would consider merging them with your branch.
Anything let me know.
Cheers!
J
Me too, took me ages to find out this information!
Glad to be of help,
Sid
I have not found this, and not sure if you can, check the Android forums and als around…
Good luck with this,
Sid
Hi Zarate,
Yeah sure no problem, i’ll review the code and I’ll keep you posted.
Sid
anyone know if this’ll work for ios too?
Hi Danny,
No this is not possible for iOS because this is a completely different operating system, with files in different places.
Greets,
Sidney
Hey this is great! I can’t believe it took me a year to stumble upon this!