What are best practices for detecting pixel ratio/density?

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

How to detect which device view you’re on using Twitter Bootstrap API?

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

Determine if the device is a smartphone or tablet? [duplicate]

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