3

I'm getting the error "The method getWindowManager() is undefined for the type LiveWallpaperService"

Since I'm creating an activity there is no way to reference that, how would I go around getting the screen width and height before the main class initialized within onCreateEngine()

It's the first thing that's called. Before I was using background image for dimensions but that's proving a pain with different screen sizes.

Can anyone please help me here? I've tried:

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

With no luck.

Also tried:

((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);

I get the error: "Activity cannot be resolved to a type"

Also:

((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))

with : "WindowManager cannot be resolved to a type"

What ever I try, where ever I place this code I always get the same error, I tried using the

onSurfaceChanged

Int with width and height but they initialize too late and my application crashes, can anyone help my here thanks?

Oliver Dixon
  • 7,012
  • 5
  • 61
  • 95

1 Answers1

10
mContext = getBaseContext();
DisplayMetrics displayMetrics = new DisplayMetrics(); 
displayMetrics = mContext.getResources().getDisplayMetrics();
mScreenWidth = displayMetrics.widthPixels;
mSreenHeight = displayMetrics.heightPixels;
Killyox
  • 99
  • 5
zyy
  • 116
  • 1
  • 3