0

Possible Duplicate:
Android - how to set the wallpaper image

I want to change the current wallpaper to another one programatically in android.Is it possible?I am doing a project that automatically changes wallpaper depending on the conditions set by the user

Community
  • 1
  • 1
Sanal Varghese
  • 1,465
  • 4
  • 23
  • 46
  • I guess its already answered at http://stackoverflow.com/questions/1964193/android-how-to-set-the-wallpaper-image – the100rabh Mar 27 '12 at 03:55

2 Answers2

2

firstly add this permission in AndroidManifest.xml file

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

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:orientation="vertical" >

    <Button
        android:layout_margin="20dp"
        android:id="@+id/set"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Set WallPaper" />
<ImageView
        android:layout_margin="20dp"
        android:id="@+id/preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         />

</LinearLayout>

then below is your java code which you to implement:

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

            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                Button buttonSetWallpaper = (Button)findViewById(R.id.set);
                ImageView imagePreview = (ImageView)findViewById(R.id.ic_launcher);
                imagePreview.setImageResource(R.drawable.five);

                buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        WallpaperManager myWallpaperManager
                        = WallpaperManager.getInstance(getApplicationContext());
                        try {
                                myWallpaperManager.setResource(R.drawable.ic_launcher);
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                    }});
             }
        }
Hiral Vadodaria
  • 19,158
  • 5
  • 39
  • 56
Pradeep Sodhi
  • 2,135
  • 1
  • 19
  • 19
0

Yes you indeed can.

public void setStream (InputStream data)

From the developers site:

Change the current system wallpaper to a specific byte stream. The give InputStream is copied into persistent storage and will now be used as the wallpaper. Currently it must be either a JPEG or PNG image. On success, the intent ACTION_WALLPAPER_CHANGED is broadcast. Parameters

data A stream containing the raw data to install as a wallpaper.

Community
  • 1
  • 1
ScottJShea
  • 7,041
  • 11
  • 44
  • 67