3

Hello There I am totally new to Android Dev. and learning it to my own. I am learning to setup a home screen wallpaper, and I have been facing a problem that my wallpaper being stretch on some devices (not all).

The problem is strange, when I set the wallpaper from my app, closes my app and come to home screen the wallpaper was not in stretched condition but suddenly within a blink of eye or a second it gets stretched on the screen or you can say it expands itself giving nearly half of the image on the screen!


Code I am trying

 DisplayMetrics metrics = new DisplayMetrics();
                      context.getWindowManager().getDefaultDisplay().getMetrics(metrics);                         

 int height = metrics.heightPixels;

 int width = metrics.widthPixels;

 Bitmap originalBitmap = BitmapFactory.decodeResource
                            (context.getResources(), id);

 Bitmap bitmap = Bitmap.createScaledBitmap(originalBitmap, width, height, true);

 WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
 wallpaperManager.setWallpaperOffsetSteps(1, 1);
 wallpaperManager.suggestDesiredDimensions(width, height);
 wallpaperManager.setBitmap(bitmap);
 Toast.makeText(MainActivity.mainActivity, "Wallpaper set", Toast.LENGTH_SHORT).show();
 Log.e("xxx",""+width+" & "+height);

I am facing this problem on some device and not on all of the devices!

Any help would be appreciated, Thanks in advance

Java Nerd
  • 958
  • 3
  • 19
  • 51

1 Answers1

0

Have u tried to include dp(dots per inch ) in your width height calculation of bitmap?

surya
  • 607
  • 5
  • 18