Get current wallpaper

本小妞迷上赌 提交于 2019-11-27 02:19:48

问题


I'm pretty new to Android programming so bear with me.

I was wondering if there was a method of retrieving the current wallpaper on an android device and saving it to a variable in your app's code.

Thanks


回答1:


final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();



回答2:


This is the good way to do that:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();



回答3:


This goes a step further and saves the file. You'll need exception handling of course and you'll need external write permission.

import java.io.FileOutputStream;
import android.graphics.Bitmap;
import android.app.WallpaperManager;

WallpaperManager wmInstance = WallpaperManager.getInstance(context);

wmInstance
    .getDrawable()
    .getBitmap()
    .compress(Bitmap.CompressFormat.PNG, 100,
        new FileOutputStream("/storage/emulated/0/output.png"))


来源:https://stackoverflow.com/questions/9939329/get-current-wallpaper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!