Phate Phate - 10 months ago 96
Android Question

Programmatically set android phone's background

I'd like to allow the user to choose a background from a list of images, the user clicks on one of them and that image is used as background for his phone.
My app should simply be another version of the android default gallery.

Is it possible to programmatically set the phone's wallpaper?

Answer Source

First one, you need set the permission in your Manifest.xml file

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

And you can set the background with this:

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

That works