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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With