Saturday, January 21, 2012

Android - How to set the wallpaper image

AIM: To set wallpaper from your program
Solution:

If you have Image path. like /sdcard/image1.jpg


FileInputStream is = new FileInputStream(new File(imagePath));
BufferedInputStream 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 trying to set wallpaper");
    wallpaperManager = WallpaperManager.getInstance(this);
    wallpaperDrawable = wallpaperManager.getDrawable();
    wallpaperManager.setBitmap(useThisBitmap);
}
 
Add this in Manifest file 
 
<manifest xlmns:android...>
 ...
 <uses-permission android:name="android.permission.SET_WALLPAPER" />
</manifest>
 
 

 
 
 
 



No comments:

Post a Comment

Android Developers Blog

Ram's shared items

Amazon Product Ads