尝试设置壁纸时出现以下错误

时间:2016-08-06 03:06:40

标签: java android

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

错误:可疑转换为WallpaperManager获取WALLPAPER_SERVICE:   预期WallpaperService [ServiceCast] this.manager =   (WallpaperManager)   context.getSystemService(Context.WALLPAPER_SERVICE);

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您应该使用getInstance()的{​​{1}}方法来获取实例。

更改以下内容:

WallpaperManager

对此:

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