Android - How to set the wallpaper image? [duplicate]
Possible Duplicate:
Android - how to set the wallpaper image
What i'm trying to do is, set the wallpaper using an image URI (no cropping)
I'm a noob at dev on Android and dev in general. The internet has failed me... on providing code to set the wallpaper.
yes the dev resource site says
public void setStream (InputStream data)
but i don't understand it, some sample code would greatly help me.
Hi you can use this code if You have Image path.
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 .
If you have the image URL you can open the resource it represent using the stream(abstraction):
new URL("your.image.url.com").openStream()
. This method call will return an object of type InputStream
which you can pass as an argument to setStream()
method.
If you dont want to specify a stream directly, you can open the remote stream, create a Bitmap and then either use a WallpaperManager instance or do a context.setWallpaper(bitmap)
(this is deprecated) to set your bitmap as the wallpaper.
For reference take a look at this thread.
精彩评论