Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using getWindowManager() inside BroadcastReceiver

I am trying to use getWindowManager() inside BroadcastReceiver and I get this error:

"The method getWindowManager() is undefined for the type MyReceiver"

I just need to get display.getWidth() and display.getHeight()

Any hints? Thanks a lot.

like image 823
Ton Avatar asked Jun 08 '12 19:06

Ton


1 Answers

Simple code you only need context

        DisplayMetrics metrics = new DisplayMetrics();         WindowManager windowManager = (WindowManager) context                 .getSystemService(Context.WINDOW_SERVICE);         windowManager.getDefaultDisplay().getMetrics(metrics); 

More info go to documentation

Or you can use this one

context.getResources().getDisplayMetrics() 

but read documentation

Return the current display metrics that are in effect for this resource object. The returned object should be treated as read-only.

like image 72
Dawid Avatar answered Oct 09 '22 03:10

Dawid