Android Get Screen dimensions from Service

后端 未结 4 2064
Happy的楠姐
Happy的楠姐 2021-02-02 08:35

I got the Screen Size by using the following from a activity,

Display display = getWindowManager().getDefaultDisplay();

But the same thing is n

4条回答
  •  一个人的身影
    2021-02-02 08:41

    It worked for me!

    DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    

    You only needed to get the context.

提交回复
热议问题