How do I check device density of android device inside html page? I tried below code but not working for android device -
if($(window).devicePixelRatio == 1) {
a1=a1+a1*5;
}
else if($(window).devicePixelRatio == 2) {
a1=a1+a1*10;
}
you can get device density by using javaScriptInterFace.
wv.addJavascriptInterface(new JavaScriptInterface(context),
"jsInterface");
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public float getDensity() {
return scale = mContext.getResources().getDisplayMetrics().density;
}
}
and in your html get density by javascript
var scale = jsInterface.getDensity();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.