I am developing an application that shows the different photos from server and user can set selected photos as wallpaper of its device i used given code to set wallpaper it working but image was not set properly it not fit to screen. I used this code.
String dirPath = getFilesDir().toString();
String folder = mPhotos.get(nextPosition - 1).getCategory();
String filePath = dirPath + "/PhotoViewer/" + folder + "/"
+ mPhotos.get(nextPosition - 1).getFileName();
File imageFile = new File(filePath);
Bitmap bitmap = BitmapFactory.decodeFile(imageFile
.getAbsolutePath());
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
try {
myWallpaperManager.setBitmap(bitmap);
Toast.makeText(PhotoActivity.this, "Wallpaper set",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(PhotoActivity.this, "Error setting wallpaper",
Toast.LENGTH_SHORT).show();
}
Please help me out.
Hello,
ReplyDeletehow to use this code for set wallpaper from my site/gallery web? and not from local dir?
Thanks.