I\'m creating an enterprise app for my company that will only run on a company provided 7\" tablet which is rooted and running Android 4.2.2. A requirement is that when the
After further investigation i discovered that when i run these commands, the wallpaper only disappears when it was an image and not a live wallpaper or video wallpaper.
I realise that this is quite specific to an uncommon scenario, but I thought I would share my solution in the event that it may help somebody else in the future. I hoped that there was a command that i could run that would resolve this but couldn't find anything so I decided to refresh the wallpaper programmatically. WallpaperManager doesn't have a refresh method at this stage so I just get the existing wallpaper image and then set the wallpaper to that image. A bit of a hack but in my opinion it is better than leaving the user with a black wallpaper.
private void refreshWallpaper() {
try {
WallpaperManager wallpaperManager =
WallpaperManager.getInstance(context);
WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo();
// wallpaperInfo is null if a static wallpaper is selected and
// is not null for live wallpaper & video wallpaper.
if (wallpaperInfo == null) {
// get the existing wallpaper drawable
Drawable wallpaper = wallpaperManager.peekDrawable();
// convert it to a bitmap
Bitmap wallpaperBitmap = drawableToBitmap(wallpaper);
// reset the bitmap to the current wallpaper
wallpaperManager.setBitmap(wallpaperBitmap);
}
} catch (Exception e) {
// TODO: Handle exception as needed
e.printStackTrace();
}
}
private static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}