Skip to content

Instantly share code, notes, and snippets.

@androhi
Created September 10, 2012 05:19
Show Gist options
  • Save androhi/3689013 to your computer and use it in GitHub Desktop.
Save androhi/3689013 to your computer and use it in GitHub Desktop.
Androidで画面サイズを取得する方法 ref: http://qiita.com/items/c1171b4904b312c9023a
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
overrideGetSize(display, size);
void overrideGetSize(Display display, Point outSize) {
try {
// test for new method to trigger exception
Class pointClass = Class.forName("android.graphics.Point");
Method newGetSize = Display.class.getMethod("getSize", new Class[]{ pointClass });
// no exception, so new method is available, just use it
newGetSize.invoke(display, outSize);
} catch(NoSuchMethodException ex) {
// new method is not available, use the old ones
outSize.x = display.getWidth();
outSize.y = display.getHeight();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment