warning: [deprecation] scaledDensity in DisplayMetrics has been deprecated

Reference: https://developer.android.com/reference/android/util/DisplayMetrics#scaledDensity

This method is deprecated from API level 34, so if you want to get the dimensions of the application window then you can safely manage this situation with:

DisplayMetrics dm = getResources().getDisplayMetrics();
float scaledDensity;
if (Build.VERSION.SDK_INT >= 34)
    scaledDensity = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm);
else
    scaledDensity = dm.scaledDensity;

2 Replies to “warning: [deprecation] scaledDensity in DisplayMetrics has been deprecated”

  1. Your calculation is not correct. Value of your `scaledDensity` calculation is the same as `getResources().getDisplayMetrics().density`.

Leave a Reply

Your email address will not be published. Required fields are marked *