How to check device in phonegap?.Actually i need that my application is only run only tablet or in Iphone .I need to block my application on other phones only run Android ta
Cordova "out-of-the-box" can't determine if a device is a tablet.
For iOS, a simple bit of Javascript can be used to detect if the device is an iPad by examining the user agent string:
var isTablet = !!navigator.userAgent.match(/iPad/i);
However, for Android, JS isn't good enough, it requires some native Java:
private boolean isTabletDevice(Context applicationContext) {
boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) >=
Configuration.SCREENLAYOUT_SIZE_LARGE);
if (device_large) {
DisplayMetrics metrics = new DisplayMetrics();
Activity activity = this.cordova.getActivity();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
|| metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
|| metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
|| metrics.densityDpi == DisplayMetrics.DENSITY_TV
|| metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
Log.d(LOG_TAG, "Is Tablet Device");
return true;
}
}
Log.d(LOG_TAG, "Is NOT Tablet Device");
return false;
}
This plugin wraps up both these approaches in an easy-to-use package for Android and iOS: https://github.com/dpa99c/phonegap-istablet.