Oliver Dixon
Oliver Dixon

Reputation: 7424

Where do I use getWindowManager() within Live Wallpaper?

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?

Upvotes: 3

Views: 4597

Answers (1)

zyy
zyy

Reputation: 116

mContext = getBaseContext();
DisplayMetrics displayMetrics = new DisplayMetrics(); 
displayMetrics = mContext.getResources().getDisplayMetrics();
mScreenWidth = displayMetrics.widthPixels;
mSreenHeight = displayMetrics.heightPixels;

Upvotes: 10

Related Questions