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
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
This is the good way to do that:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
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"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.