Monday, July 23, 2012

Verify Android Device screen resolutions as with your Application Tests


This post can help you to verify the height and width of  Android Device Screen resolutions along with your application tests

public void testScreenResolution(){           
Context mContext = getInstrumentation().getContext().getApplicationContext();
// Here the Height of Screen expected value is 480
assertEquals(480,getScreenHeight(mContext));
// Here the Width of Screen expected value is 320
assertEquals(320,getScreenWidth(mContext));         
}

public static int getScreenWidth(Context context){
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
return display.getWidth();
      }
   
public static int getScreenHeight(Context context){
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
return display.getHeight();
}