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
  • 908
  • 3
  • 18
  • 51
  • Would be great to know on which devices you face that problem and android version of them. Also would be great to have image itself in order to reproduce problem. – Divers Sep 05 '16 at 14:42
  • Huawei devices :( – Java Nerd Sep 05 '16 at 14:44
  • can u post some more codes – W4R10CK Sep 05 '16 at 14:48
  • what kind of some more code? this is all i have to set the wallpaper! – Java Nerd Sep 05 '16 at 14:51
  • @JavaNerd you didn't answer my question – Divers Sep 05 '16 at 18:07
  • @Divers I have already answered your question "Huawei devices :(", They are Android 4.0+ that's what I could answer – Java Nerd Sep 05 '16 at 18:20
  • Can you share some screenshots? – Hitesh Sahu Sep 07 '16 at 12:35
  • You are using [WallpaperManager](https://developer.android.com/reference/android/app/WallpaperManager.html) to set images in background without providing any option like (cropping and adjusting images). so my suggetion is, why don't you use Intent to send your bitmap to gallery app where you can crop your images and set it as wallpaper. – pike Sep 12 '16 at 11:22

1 Answers1

0

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

surya
  • 599
  • 4
  • 17