开发者

How to set wallpaper in Android? [duplicate]

开发者 https://www.devze.com 2023-01-10 04:34 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Android - how to set the wallpaper image
This question already has answers here: Closed 11 years ago.

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.


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?


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 .


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消