Android setting wallpaper gone wrong

橙三吉。 提交于 2019-12-07 05:08:22

问题


So I was developing wallpaper changer long time ago and got it released. After a while I started receiving comment the wallpaper not resizing correctly. Also I tried on different sizes of emus and they were right. I scale the bitmap correctly etc. but somehow android tends to rescale the wallpaper even bigger! Is there way to avoid that? My code:

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've been trying other ways too but nothing seems help, even if I afterwards check if the rescaled wallpaper is right size etc. :( Any ideas?


回答1:


I suppose you could resize the wallpapers using the size specified by WallpaperManager.getDesiredMinimumWidth() and WallpaperManager.getDesiredMinimumHeight(), instead of the display size. That way, even the requirements set by custom home applications (like those possibly set by device manufacturers and/or service providers) will be respected, meaning a (much) larger compatibility for your app.




回答2:


I had the same problem, after resize wallpaper had the same size, but diffrent resolution.

In my case that code solved problem:

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

        int height = metrics.heightPixels;
        int width = metrics.widthPixels;

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



回答3:


I had to create overlay image.

  1. Create a blank image with size of WallpaperManager.getDesiredMinimumWidth() x WallpaperManager.getDesiredMinimumHeight()

  2. Resize your bitmap to screen size with, Display display = getWindowManager().getDefaultDisplay(); bmp = Bitmap.createScaledBitmap(bmp, display.getWidth(), display.getHeight(), false);

  3. Overlay your wallpaper on center of blank image. And set Overlay as wallpaper.



来源:https://stackoverflow.com/questions/8885958/android-setting-wallpaper-gone-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!