Setting an image as a wallpaper


This is a sample application to show that how to set an image as a Wallpaper.

Underlying Algorithm:

Basic description of algorithm in step by step form:
1.) Create a Project SetWallpaper.
2.) Add the relevant permissions to your AndroidManifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <uses-sdk android:minSdkVersion="9" />
    <uses-permission android:name="android.permission.SET_WALLPAPER">

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SetWallpaper" android:label="@string/app_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

3.) Put some images in the res/drawable.
4.) Run the application.

Steps to Create:

1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. SetWallpaper. Enter following information:
Project name: SetWallpaper
Build Target: Android 2.3
Application name: SetWallpaper
Package name: com.example.SetWallpaper
Create Activity: SetWallpaper

On Clicking Finish SetWallpaper code structure is generated with the necessary Android Packages being imported along with SetWallpaper class will look like following:

package com.example.SetWallpaper;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class SetWallpaper extends Activity {
    Bitmap bitmap;
    int lastImageRef;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        Button buttonSetWallpaper = (Button)findViewById(;
        ImageView imagePreview = (ImageView)findViewById(;
        buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
	    public void onClick(View arg0) {
		// TODO Auto-generated method stub
		WallpaperManager myWallpaperManager 
		= WallpaperManager.getInstance(getApplicationContext());
		try {
		} catch (IOException e) {
			// TODO Auto-generated catch block

Output –The final output:

3 Responses

  1. srinivas says:

    dear sir i\’ve a doubt the above example gives only one image at a time which we explicitly add to imagePrieview.setImageResource(R.drawable.kiss);

    so how can we write code for more than one image display as preview and select one and set as wall paper.

  2. kokesh says:

    id cannot be resolved or is not a field at “Button buttonSetWallpaper = (” line + on few under) – I do have everything exactly as it is here. Any idea?

  3. eldy says:

    my image blur when set as background, can you explain more about the size..

Leave a Reply

three + = 10

Proudly designed by Theme Junkie.