Inside your Activity: override fun onStart() { val size = Point() if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { requireContext().display!!.getRealSize(size) } else { val windowManager = requireContext().getSystemService(Context.WINDOW_SERVICE) as WindowManager windowManager.defaultDisplay.getRealSize(size) } size.x // Width size.y // Height }
Share this post
How to get Android's screen width and height
Share this post
Inside your Activity: override fun onStart() { val size = Point() if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { requireContext().display!!.getRealSize(size) } else { val windowManager = requireContext().getSystemService(Context.WINDOW_SERVICE) as WindowManager windowManager.defaultDisplay.getRealSize(size) } size.x // Width size.y // Height }