Getter for defaultDisplay: Display!’ is deprecated. Deprecated in Java

defaultDisplay was marked as deprecated in API level 30 (Android R) and above.
This means if you have a minimum SDK configuration below API level 30, you should have both implementations with the old deprecated code and the new recommended code.

After fixing the problem correctly you can use @Suppress(“DEPRECATION”) to suppress warnings

Example: Kotlin solution

    val outMetrics = DisplayMetrics()

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
        val display = activity.display
        display?.getRealMetrics(outMetrics)
    } else {
        @Suppress("DEPRECATION")
        val display = activity.windowManager.defaultDisplay
        @Suppress("DEPRECATION")
        display.getMetrics(outMetrics)
    }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)