I am developing an Android app for our company which sets the wallpaper to a specific company wallpaper every time the phone is booted. It would be preferable to check to see if the wallpaper has been changed rather than running the code to change the wallpaper.
Is there any way to get identifying information (e.g. filename etc.) from the current wallpaper?
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo();
returns null
for wallpaperInfo
.
Code for wallpaper change:
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();
}
}