Code Snippet: Detecting BB10 Devices in AIR

When programming multi-platform apps, it’s sometimes important to know whether you’re running on a certain type of devices.

This is usually stored in the┬áCapabilities.os string, and BB10 is no different. To check whether you’re on BB10 you can run the following check:

0
1
2
//Capabilities.os is 'qnx 8.0.0 blackberry 10'
var os:String = Capabilities.os.toLowerCase();
var isBB10:Boolean = ( os.indexOf("blackberry") > -1);

Here’s an example of some production code I use for all devices:

0
1
2
3
4
5
6
7
8
9
10
_deviceName = defaultDevice;
var os:String = Capabilities.os.toLowerCase();
if(os.indexOf("playbook") > -1 || os.indexOf("blackberry") > -1){
	_deviceName = BLACKBERRY;
} else if(os.indexOf("iphone") > -1){
         //iPhone OS 4.3.3 iPad2,1
	_deviceName = (os.indexOf("ipad") > -1) ? IPAD : IPHONE;
} else if(Capabilities.manufacturer.toLowerCase().indexOf("android") > -1 || 
	os.indexOf("android") > -1){
	_deviceName = ANDROID;
}

Written by

No Comments Yet.

Leave a Reply

Message