Skip to content

Instantly share code, notes, and snippets.

@jonrysimbolon
Last active April 19, 2024 12:57
Show Gist options
  • Save jonrysimbolon/c7ad7144b17e71c3261e13c008e00e0f to your computer and use it in GitHub Desktop.
Save jonrysimbolon/c7ad7144b17e71c3261e13c008e00e0f to your computer and use it in GitHub Desktop.
Deprecated "windowManager.defaultDisplay.getMetrics(displayMetrics)"
private fun screenValue() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val defaultDisplay =
DisplayManagerCompat.getInstance(this).getDisplay(Display.DEFAULT_DISPLAY)
val displayContext = createDisplayContext(defaultDisplay!!)
val width = displayContext.resources.displayMetrics.widthPixels
val height = displayContext.resources.displayMetrics.heightPixels
Log.e(tag, "width (ANDOIRD R/ABOVE): $width")
Log.e(tag, "height (ANDOIRD R/ABOVE) : $height")
} else {
val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getMetrics(displayMetrics)
val height = displayMetrics.heightPixels
val width = displayMetrics.widthPixels
Log.e(tag, "width (BOTTOM ANDROID R): $width")
Log.e(tag, "height (BOTTOM ANDROID R) : $height")
}
}
@Dubemtopsite
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment