2

I want to get the dpi of the device's screen but when I use:

          DisplayMetrics m = getResources().getDisplayMetrics();
                float den = m.density;

I get the full DisplayMetrics object as zero (I saw it in the debugging). It was the same also in my emulator (android 2.3) and on my phone (Htc Legend android 2.1 update 1). The code is located in my activity class(extends Activity) and then

WebView.setWebChromeClient(new MyWebChromeClient() {

        public void onProgressChanged(WebView view, int progress) {

              DisplayMetrics m = getResources().getDisplayMetrics();
                float den = m.density;

}

How can I fix It?

Thank You,

Boaz

4

1 回答 1

4

取自这里

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
     case DisplayMetrics.DENSITY_LOW:
                break;
     case DisplayMetrics.DENSITY_MEDIUM:
                 break;
     case DisplayMetrics.DENSITY_HIGH:
                 break;
}

试试看,然后带着结果回到这里 :)

干杯

于 2013-06-28T11:55:21.503 回答