Scaling to full screen / specific resolution

Jimmy

Active Member
Joined
Jan 2, 2020
You can use getRealSize to get the screen resolution. It's officially supported in API 17 and higher, but it actually existed in the SDK since API 14. If you use the SDK platform for API 17 or higher, you can access the method normally and just bypass the warning about it only being available in API 17.
Java:
/**
 * Gets the device's native screen resolution rotated
* based on the device's current screen orientation.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) //To remove warning about using
                                               //getRealSize prior to API 17
private Point screenResolution() {
    WindowManager windowManager =
        (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point screenResolution = new Point();

    if (Build.VERSION.SDK_INT < 14)
        throw new RuntimeException("Unsupported Android version.");
    display.getRealSize(screenResolution);

    return screenResolution;   
}
screens-densities.png
 
Top Bottom