The function “getWindowManager()” does not exist.

edited October 2017 in Android Mode

Hi all! I am working on an android app and need to get screen size in cm to make it compatible with all devices. For that, I found this function in another discussion:

import android.view.WindowManager;
import android.util.DisplayMetrics;

import android.os.Bundle;

DisplayMetrics metrics;

//code like setup and draw etc.

void onCreate(Bundle bundle) 

      metrics = new DisplayMetrics();

float getXdpi()
      return metrics.xdpi;

float getYdpi()
      return metrics.ydpi;

However, when I paste it to my code, the getWindowManager.getDefaultDisplay.getMetrics(metrics) gets underlined, specifically the getWindowManager part and it says that such a function does not exist.

What could be the problem?


Sign In or Register to comment.