Android Scrollable Wallpaper On Screen's Phone Programmatically
I am developing a wallpaper application in Android and i am finding a right way to set scrollable wallpaper for my app. Now, my code can set wallpaper from bitmap but it was croppe
Solution 1:
Post is old but anyway... You can try something similar to this
public static void setWallpaper(Context context) {
int wallpaperRId = getWallpaperImageRid(context);
if (wallpaperRId == 0) {
return;
}
Bitmap tempBmp = BitmapFactory.decodeResource(context.getResources(), wallpaperRId);
// get size
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
int area = width * height / 1000;
width *= 2;
float scale = width / (float) tempBmp.getWidth();
height = (int) (scale * tempBmp.getHeight());
Bitmap bitmap = Bitmap.createScaledBitmap(tempBmp,width,height, true);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(width, height);
try {
wallpaperManager.setBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
Post a Comment for "Android Scrollable Wallpaper On Screen's Phone Programmatically"