0

I want to set images as wallpaper in android.Those images will come one by one after some interval or like slideshow.I can set one image as wallpaper. but i want to set images that, those will come one by one after some interval or like slideshow.Any help please.

package com.sample.setwallpapaper;

public class MainActivity extends Activity {

Bitmap bitmap;
int ImageRef;


@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    Button buttonSetWallpaper = (Button)findViewById(R.id.button1);
    ImageView imagePreview = (ImageView)findViewById(R.id.imageView1);

    imagePreview.setImageResource(R.drawable.five);
    buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View arg0) {

            WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());

            try {
               myWallpaperManager.setResource(R.drawable.five);
            } 
            catch (IOException e) 
            {
               e.printStackTrace();
            }
       }

    });
}
Decoy
  • 1,598
  • 12
  • 19
DroidRid
  • 1
  • 3
  • 1
    You can use `Timer` or `Count down Timer` or `Handler` for that. First thing is that do some goggling so you will get better solution. – Piyush Aug 22 '14 at 10:51
  • You can check this link http://stackoverflow.com/questions/9732812/android-app-to-change-wallpaper-at-regular-intervals-using-timer – Piyush Aug 22 '14 at 11:07

1 Answers1

1
  1. Create an array which stores the image resource references which you want to show in slide show.

  2. Create a private referenced timer with Repeating TimerTask and set the time interval after which you want to change image.

  3. Take a private referenced int counter and set it's default value to 0.

  4. After each call to timerTask increase the counter until it reached to the count of image res array then reset it again.

  5. Make sure you set the image inside TimerTask using the post() method of imageView instance.

  6. And last but not the least don't forget to cancel & purge the timer on onStop() call otherwise timertask might get called from background and your app gets crashed.

EEJ
  • 678
  • 5
  • 12