2014-09-05 69 views
0

如何查看html頁面內的android設備密度? 我嘗試下面的代碼,但不工作的Android設備 -查看html中的android設備密度

if($(window).devicePixelRatio == 1) { 
    a1=a1+a1*5; 
} 
else if($(window).devicePixelRatio == 2) { 
    a1=a1+a1*10; 
} 

回答

1

您可以通過使用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
+0

其工作..謝謝你.. – 2014-09-05 10:15:56