Android has a way to set the home screen wallpaper. The user taps "menu" and then selects "wallpaper" to set a wallpaper from the system. The resulting wallpaper image is properly scaled in both portrait and landscape mode.
I did a small app that allows the home screen wallpaper to be changed. It works fine but I can't find out what the secret is to get the image to be the correct size after it's set as a wallpaper.
I did this with png images that are 1280x1084 and also tried the same thing with images that are 320x240 and they all are shown the same size when set as a home screen wallpaper.
I looked for tutorials and examples on how to set a wallpaper like they do, but couldn't find out how to do it. Can you show me a code sample showing me the secret to this so the resulting wallpaper is scaled correctly?
I'm sure there must be some kind of WallpaperManager setting to use but I don't know which one to use.
Thanks in advance.
Here's the code I'm using to set the wallpaper:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(R.drawable.kabanight1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Truly, Emad