简体   繁体   English

获取当前壁纸

[英]Get current wallpaper

I'm pretty new to Android programming so bear with me.我对 Android 编程还很陌生,所以请耐心等待。

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.我想知道是否有一种方法可以在 android 设备上检索当前壁纸并将其保存到应用程序代码中的变量中。

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"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM