查看html中的android设备密度
问题描述:
如何查看html页面内的android设备密度? 我尝试下面的代码,但不工作的Android设备 -查看html中的android设备密度
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意味着超高的书房sity
其工作..谢谢你.. – 2014-09-05 10:15:56