加载了过渡效果的图像时,墙纸管理器崩溃

时间:2018-08-30 16:07:19

标签: android android-bitmap android-glide android-wallpaper

我使用GlideURL加载图像并将其设置为墙纸,但是当将过渡应用于glide时,图像随过渡加载,但当图像设置为墙纸使应用程序崩溃(加载时不进行过渡,一切正常)

 java.lang.ClassCastException: android.graphics.drawable.TransitionDrawable cannot be cast to android.graphics.drawable.BitmapDrawable

这是我要加载的代码

 Glide.with(this).asBitmap()
 .load(imageUrl)
 .apply(new RequestOptions().centerCrop())
 .transition(BitmapTransitionOptions.withCrossFade())
 .into(image);

并用于应用壁纸

Bitmap bitmapImg = ((BitmapDrawable) image.getDrawable().getCurrent()).getBitmap();

            WallpaperManager wallManager = WallpaperManager.getInstance(getApplicationContext());
            try {
                wallManager.clear();
                wallManager.setBitmap(bitmapImg);

                Snackbar.make(view, "Wallpaper set successfully", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

            } catch (IOException ex) {
                Toast.makeText(fullscreen.this, "Error!", Toast.LENGTH_SHORT).show();
            }

0 个答案:

没有答案