Although there is an acceptable answer here, I am posting another answer. The reason for this is as follows. Passing contexts is not always a good idea for imho, because in some cases (for example, in application libraries, for example), contexts should not create additional and unnecessary dependencies from the application. The code is simple:
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
It provides a solution for cases where the known limitations of this method are not important to the developer. According to Android documentation:
getSystem() returns a global resource share that provides access only to system resources (without application resources) and is not configured for the current screen (cannot use units, does not change depending on orientation, etc.).
In any case, all DisplayMetrics fields are populated with meaningful information. In my case, it was the DPI that I was. And the method provides me with DPI without context.
Stan May 18 '13 at 21:38 2013-05-18 21:38
source share