问题
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