Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap - Detect device type in phonegap

I'm building an application in phonegap for the three different platforms: Android, iOS And Blackberry. While doing so, I have to detect the device type so that I can manage the height and width of my app on different platforms and for different devices like Android Phone, Android Tablet, iPhone, iPad and Blackberry...

like image 920
Preet_Android Avatar asked Jun 18 '12 06:06

Preet_Android


3 Answers

New in Phonegap, and simplest, is that you can use the device.platform:

// Depending on the device, a few examples are:
//   - "Android"
//   - "BlackBerry"
//   - "iOS"
//   - "webOS"
//   - "WinCE"
//   - "Tizen"
//   - "browser"
var devicePlatform = device.platform;
like image 143
Sindre Avatar answered Nov 07 '22 10:11

Sindre


if you want to get device type before onDeviceReady, you can get like this.

var deviceType = (navigator.userAgent.match(/iPad/i))  == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i))  == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";

alert(deviceType);
like image 44
JDev Avatar answered Nov 07 '22 11:11

JDev


cordova.platformId 
// "android"
like image 37
RouR Avatar answered Nov 07 '22 10:11

RouR