2012-06-08 11 views
40

estoy tratando de utilizar getWindowManager() dentro BroadcastReceiver y me sale este error:usando getWindowManager() dentro BroadcastReceiver

"El método getWindowManager() no está definida para el tipo MyReceiver"

que sólo tiene que conseguir display.getWidth() y display.getHeight()

¿Alguna pista? Muchas gracias.

Respuesta

101

Código de ejemplo sólo es necesario contexto

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

Más información ir a documentation

o puede utilizar éste

context.getResources().getDisplayMetrics() 

pero leer la documentación

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

Cuestiones relacionadas