Android wallpapers have not changed

So, I have been developing a wallpaper changer for a long time and got it. After some time, I began to receive comments so that the wallpaper did not change correctly. Also I tried different sizes of emus and they were right. I am scaling the bitmap correctly, etc., but somehow the android tends to scale the wallpaper even more! Is there any way to avoid this? My code is:

Display display = parent.getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Bitmap scaled = Bitmap.createScaledBitmap(wallpaper, width, height, true); WallpaperManager wm = WallpaperManager.getInstance(getContext()); wm.setBitmap(scaled); 

I also tried other methods, but nothing helps, even if I later check if the wallpaper is changed correctly, etc. :( Any ideas?

+4
source share
3 answers

I assume that you can resize the wallpaper using the size specified by WallpaperManager.getDesiredMinimumWidth () and WallpaperManager.getDesiredMinimumHeight () instead of the size of the display. In this way, even the requirements set by custom home applications (such as possibly set by device manufacturers and / or service providers) will be met, which means (greater) greater compatibility for your application.

0
source

I had the same problem after the size of the wallpaper was the same size but different resolution.

In my case, the problem with the code is resolved:

 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; Bitmap bitmap = Bitmap .createScaledBitmap(whatever, width, height, true); 
0
source

I had to create an overlay image.

  • Create an empty image of size WallpaperManager.getDesiredMinimumWidth() x WallpaperManager.getDesiredMinimumHeight()

  • Change the size of the bitmap to the screen size, Display display = getWindowManager().getDefaultDisplay(); bmp = Bitmap.createScaledBitmap(bmp, display.getWidth(), display.getHeight(), false);

  • Apply wallpaper to the center of the blank image. And set Overlay as your wallpaper.

0
source

Source: https://habr.com/ru/post/1391327/


All Articles