检查html中的android设备密度
如何在html页面中检查android设备的设备密度? 我尝试了以下代码,但不适用于android设备-检查html中的android设备密度,android,html,css,Android,Html,Css,如何在html页面中检查android设备的设备密度? 我尝试了以下代码,但不适用于android设备- if($(window).devicePixelRatio == 1) { a1=a1+a1*5; } else if($(window).devicePixelRatio == 2) { a1=a1+a1*10; } 您可以使用javaScriptInterFace获得设备密度 wv.addJavascriptInterface(new JavaScriptInterfa
if($(window).devicePixelRatio == 1) {
a1=a1+a1*5;
}
else if($(window).devicePixelRatio == 2) {
a1=a1+a1*10;
}
您可以使用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;
}
}
在html中,通过javascript获取密度
var scale = jsInterface.getDensity();
- 0.75表示低密度
- 1.0表示标准(中等)密度
- 1.5表示高(大)密度
- 2.0表示超高密度