1

Possible Duplicate:
Android - how to set the wallpaper image

I hav started doing app in Android. I want to set wallpaer in Android which run in Background(using Service) and the wallpaper will change within 5 minute in background. I keep the image files in Drawable. Anyone kindly send the coding for setting the wallpaer and retriving it after 5 minutes..

Thanx in Advance.

Community
  • 1
  • 1
Subrat
  • 3,928
  • 6
  • 39
  • 48

3 Answers3

6

Here is an example. But unfortunately it does not work for me. Basically I am using the following code:

Code:

    WallpaperManager myWallpaperManager = WallpaperManager
            .getInstance(this);  
    String imageFilePath = getFilePath(imageUri);
    Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath);
    if (myBitmap != null) {  
        try {  
            myWallpaperManager.setBitmap(myBitmap);  
        } catch (IOException e) {  
            showToast(ImageDisplay.this,
                    "Failed to set Backgroundimage");  
        }  
    } else {  
        showToast(ImageDisplay.this, "Failed to decode image.");  
    }

The imageFilePath is correct as far as I can tell (as I also for different stuff that is working). There is no error or exception. The background of my phone is just empty after calling this app. What am I doing wrong?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Redfox
  • 1,024
  • 1
  • 11
  • 28
2
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
 if(imagePath!=null){
   System.out.println("Hi I am try to open Bit map");
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);

................................................. if you have image URI then use this

wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);

.............. Let me know if there is any issue .

Vinoth
  • 1,339
  • 6
  • 23
  • 42
Maidul
  • 1,289
  • 16
  • 30
0

You may want to look at the WallpaperManager.
Write a simple service and you could use a Timer to change the Wallpaper at regular intervals.

codinguser
  • 5,562
  • 2
  • 33
  • 40