androidaccessibility

Getting the Accessibility Display Size Programmatically Android


I need to record certain metrics for the usage of my app based on font and display size. How can I retrieve the display size under Settings -> Accessibility section programmatically? Font Scale is straight-forward, but there seems to be no way of retrieving the display size.

float fontScale = getResources().getConfiguration().fontScale;

Solution

  • The Android API does not expose this scale factor chosen by the user. However, a similar scale can be obtained by dividing the density DPI (which is scaled based on the user's setting) and DENSITY_DEVICE_STABLE, which gives the required result.

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    final int currentDeviceDensity = metrics.densityDpi;
    float displayDensityScaleFactor = (float) currentDeviceDensity / DENSITY_DEVICE_STABLE;