Android 设置flutter assets 文件夹下的图片为壁纸

133 阅读1分钟

设置壁纸代码

  Thread {
                    try {
                        val bitmap = BitmapFactory.decodeStream(context.assets.open(filePath))
                        val mWallManager = WallpaperManager.getInstance(this@MainActivity)
                        mWallManager.setBitmap(bitmap)
                    } catch (e: IOException) {
                        e.printStackTrace()
                    }
                }.start()

filePath 为flutter传递的图片路径 一般长这样

"flutter_assets/$imgPath"

flutter_assets 是固定的 imgPath 就是你在flutter中使用图片的路径。

glide 加载

Glide.with(context)
    .asGif()
    .load("file:///android_asset/flutter_assets/assets/anim/icon_power_2.gif")
    .into(gifIv!!)