0

I have my initial

public class myapplication extends Application {
}

which is starting before any activity is started.

How can I access the getWindowManager() to get screen properties ?

I would like to calculate the screeninches (which I know how to do in general) before I started an activity.

mcfly soft
  • 11,289
  • 26
  • 98
  • 202

2 Answers2

0

Well you can use DisplayMetrics from resources

public class myapplication extends Application {

   public DisplayMetrics getMetrics(){
      return getResources().getDisplayMetrics(); 
   }

}
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
0

You can also use

import android.app.Application;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();

        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);
        System.out.println("Screen width =" + dm.widthPixels);
        System.out.println("Screen height =" + dm.heightPixels);

    }
}

and to get screen size in inches How to get android device screen size?

Pankaj Kant Patel
  • 2,050
  • 21
  • 27