我正在为我们公司开发一个 Android 应用程序,每次启动手机时都会将壁纸设置为特定的公司壁纸。最好检查墙纸是否已更改,而不是运行代码来更改墙纸。
有没有办法从当前壁纸中获取识别信息(例如文件名等)?
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo();
返回. null
_wallpaperInfo
壁纸更换代码:
public static void setWallpaper(Context context) {
// Has wallpaper changed?
if (/*--wallpaperNotChanged--*/) {
return;
}
try {
// Setup
Drawable drawable = context.getResources().getDrawable(R.drawable.test);
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
// Get display sizes
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
// Create Bitmap
Bitmap unscaledWallpaper = BitmapFactory.decodeResource(context.getResources(), R.drawable.test);
Bitmap wallpaper = Bitmap.createScaledBitmap(unscaledWallpaper, displayMetrics.widthPixels, displayMetrics.heightPixels, true);
// Set wallpaper
wallpaperManager.setBitmap(wallpaper);
} catch (Exception e){
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}