wrong screen size when reading using getrealmetrics

Viewed 29

t tested on Vivo V1981A. Device screen resolution is 1080,2408 pixels.

I have got 720, 1605. Any ideas?

  DisplayMetrics pDisplayMetrics = new DisplayMetrics();
  WindowManager pWindowManager = pActivity.getWindowManager();
  Display pDisplay = pWindowManager.getDefaultDisplay();
  pDisplay.getRealMetrics(pDisplayMetrics);
  hSize[0] = 0;
  hSize[1] = 0;
  hSize[2] = pDisplayMetrics.widthPixels;
  hSize[3] = pDisplayMetrics.heightPixels;
1 Answers
val display = windowManager.defaultDisplay

        // declare and initialize a point
        val size = Point()

        // store the points related details from the 
        // display variable in the size variable
        display.getSize(size)

        // store the point information in integer 
        // variables width and height
        // where .x extracts width pixels and 
        // .y extracts height pixels
        val width = size.x
        val height = size.y

        // Toast will display the width and height values
        Toast.makeText(
            applicationContext,
            "Width: $width Pixels , Height: $height Pixels",
            Toast.LENGTH_LONG
        ).show()
Related