[英]Get current wallpaper
我對 Android 編程還很陌生,所以請耐心等待。
我想知道是否有一種方法可以在 android 設備上檢索當前壁紙並將其保存到應用程序代碼中的變量中。
謝謝
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
這是做到這一點的好方法:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
這更進一步並保存文件。 您當然需要異常處理,並且需要外部寫入權限。
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.