How to get screen display metrics in application class

前端 未结 6 549
自闭症患者
自闭症患者 2020-11-30 10:38

If I put this in some activity class it works perfectly but, when I put it in my App class the method getWindowManager() can not be found. Is there some way to

6条回答
  •  悲&欢浪女
    2020-11-30 11:39

    hope this will work for you

    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int pxWidth = displayMetrics.widthPixels;
    int pxHeight = displayMetrics.heightPixels;
    

提交回复
热议问题