Last active
April 19, 2024 12:57
-
-
Save jonrysimbolon/c7ad7144b17e71c3261e13c008e00e0f to your computer and use it in GitHub Desktop.
Deprecated "windowManager.defaultDisplay.getMetrics(displayMetrics)"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} |
@intersk thanks, i forgot it
how i can get updated function or method of any deprecated function or method where can i read
it still returns the size EXCLUDING the fucking systems bars, that's super annoying >..<
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"width = displayContext.resources.displayMetrics.widthPixels"
why not "val width = .... " ?