android service和activity获取屏幕尺寸

activity:

   DisplayMetrics dm = new DisplayMetrics();
   this.getWindowManager().getDefaultDisplay().getMetrics(dm);

   sW = dm.widthPixels;
   sH = dm.heightPixels;

service:

   DisplayMetrics dm = new DisplayMetrics();
   dm = getResources().getDisplayMetrics();
   int screenWidth = dm.widthPixels;
   int screenHeight = dm.heightPixels;

你可能感兴趣的:(Activity)