Created
September 10, 2012 05:19
-
-
Save androhi/3689013 to your computer and use it in GitHub Desktop.
Androidで画面サイズを取得する方法 ref: http://qiita.com/items/c1171b4904b312c9023a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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