Wednesday, July 31, 2013

How to Set WallPaper in Android

In this tutorial I will explain how to set Wallpaper.

To Set the Wallpaper we must declare following permission in manifest file

 <uses-permission android:name="android.permission.SET_WALLPAPER" />
 <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>

If you use an Image to set as wallpaper, The image may not fit to the Screen, it may be smaller or larger than the device screen,  To overcome this problem or if we want that Image should to the screen for all the devices with different screen sizes, we need to use DisplayMatrics.

// get the Image to as Bitmap
Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(;

                DisplayMetrics metrics = new DisplayMetrics();

                // get the height and width of screen
                int height = metrics.heightPixels;
                int width = metrics.widthPixels;
                WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
                 try {
                  wallpaperManager.suggestDesiredDimensions(width, height);
                    Toast.makeText(this, "Wallpaper Set", Toast.LENGTH_SHORT).show();
                 } catch (IOException e) {


  1. hii
    thank's for this code it's work but when i set my image as's perfect but in just one second it becomes zoomed and stretched..

    plzz give me solution

  2. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work sfondi disegni grafici

  3. Some truly nice stuff on this site, I love it. macbook device template

  4. Keep websiteing stuff like this I actually am fond of it device mockups