I am developing an app, in which the wallpaper image of the device should change at fixed intervals. I have kept the images in the drawable folder. I am using a WallpaperManager to set these images as the wallpaper.
To ensure that the app works well on various devices, I have kept multiple copies of different sized images in various folders like drawable-small,drawable-xlarge folders in the res directory. However, these do not scale properly on every device.
My question is how do I ensure that the wallpaper images fit nicely on every device. Will I have to do it programmatically? Any sample code would be of immense help. Thanks.
This is the code I have used
Drawable drawable;
WallpaperManager wpm;
@Override
public void onCreate() {
super.onCreate();
wpm=WallpaperManager.getInstance(WallAlarm.this);
drawable = getResources().getDrawable(R.drawable.two);
}
Bitmap wallpaper=((BitmapDrawable)drawable).getBitmap();
ImageView iv=new ImageView(this);
iv.setImageDrawable(drawable);
iv.setScaleType(ScaleType.FIT_XY);
try {
wpm.setBitmap(wallpaper);
} catch (IOException e) {
e.printStackTrace();
}
}
}