Detect mobile devices – and tablet devices
Here is a class with methods for detecting each platform individually. https://github.com/serbanghita/mobile-detect
Here is a class with methods for detecting each platform individually. https://github.com/serbanghita/mobile-detect
You should leverage the manufacturer’s hint via the <meta name=”viewport” content=”width=device-width”/> or @-ms-viewport {width:device-width} feature. It basically exposes the default zoom the device manufacturer considers optimal given the pixel density of the screen. After you do that, when you call window.innerWidth it will give you what your original equation was intended for but without relying … Read more
This question is a bit old but I couldn’t find a better answer when I googled it. Most desktops now are touch enabled, so detecting it is irrelevent. The best way to detect them is by screen size. With Modernizr you can use if (Modernizr.mq(‘only all and (max-width: 480px)’)) { …}
If you want to know what environment you’re on, try using Bootstrap’s own CSS classes. Create an element, add it to the page, apply its helper classes and check if it’s hidden to determine if that’s the current environment. The following function does just that: Bootstrap 4 function findBootstrapEnvironment() { let envs = [‘xs’, ‘sm’, … Read more
Use this: public static boolean isTablet(Context context) { return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; } which will return true if the device is operating on a large screen. Some other helpful methods can be found here.
The issue is that the Android User-Agent is a general User-Agent and there is no difference between tablet Android and mobile Android. This is incorrect. Mobile Android has “Mobile” string in the User-Agent header. Tablet Android does not. But it is worth mentioning that there are quite a few tablets that report “Mobile” Safari in … Read more
This subject is discussed in the Android Training: Use the Smallest-width Qualifier If you read the entire topic, they explain how to set a boolean value in a specific value file (as res/values-sw600dp/attrs.xml): <resources> <bool name=”isTablet”>true</bool> </resources> Because the sw600dp qualifier is only valid for platforms above android 3.2. If you want to make sure … Read more