Gleaces Juvilian Gleaces Juvilian - 3 months ago 25
Android Question

I get the following error when trying to set a wallpaper

public HeavyLifter(Context context, Handler callback) {
this.context = context;
this.callback = callback;
this.manager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
}



Error: Suspicious cast to WallpaperManager for a WALLPAPER_SERVICE:
expected WallpaperService [ServiceCast] this.manager =
(WallpaperManager)
context.getSystemService(Context.WALLPAPER_SERVICE);


How can i resolve this issue ?

Answer

You should use the getInstance() method of WallpaperManager to get ahold of an instance.

Change the following:

this.manager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);

To this:

this.manager = WallpaperManager.getInstance(context);
Comments