WallpaperManager zooms in even if the size matches the screen

I have an application that applies wallpaper to the main screen with images corresponding to the screen size, however on the galaxy s3 the image size increases when I apply it, although the image is used in the same way as the screen size! This is a static image and does not even scroll when switching between pages on the main screen. The strange thing is that if I applied the image using the built-in gallery, the wallpaper will be applied perfectly without scaling (it appears with the “cropping image” screen, but the cropping area itself corresponds to the edges of the image).

The code I use works fine on a number of phones (galaxy, ace 2, s2 among others), but not on s3; I was wondering if there is anything I can do to make the wallpaper fill the screen correctly? The current code that I use for wallpapering is:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); wallpaperManager.setWallpaperOffsets(wallpaperViewer.getApplicationWindowToken(), 0, 0); wallpaperManager.setBitmap(BitmapFactory.decodeFile(file.getPath()));//file is jpg on sd card 
+7
source share
4 answers

EDIT : Added Y offset correction - thanks @Jason Goff!

Good, so it turns out that the minimum width of the initial screen on s3 is not 720, but actually 1280! You can find out the desired minimum width and height of the wallpaper by calling

 wallpaperManager.getDesiredMinimumWidth();//returned 1280 on s3 wallpaperManager.getDesiredMinimumHeight();//also returned 1280 on s3 

So, in order to apply the wallpaper to the center of the screen, I had to create an empty 1280x1280 raster map on the fly, and then lay my wallpaper in the center of the empty raster image, I created a static BitmapHelper class with methods for setting bitmaps, here are the methods for creating bitmaps and image overlay Wallpaper:

 public class BitmapHelper { public static Bitmap overlayIntoCentre(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null);//draw background bitmap //overlay the second in the centre of the first //(may experience issues if the first bitmap is smaller than the second, but then why would you want to overlay a bigger one over a smaller one?!) //EDIT: added Y offest fix - thanks @Jason Goff! canvas.drawBitmap(bmp2, (bmp1.getWidth()/2)-(bmp2.getWidth()/2), (bmp1.getHeight()/2)-(bmp2.getHeight/2), null); return bmOverlay; } public static Bitmap createNewBitmap(int width, int height) { //create a blanks bitmap of the desired width/height return Bitmap.createBitmap(width, height, Config.ARGB_8888); } } 

and all my code uses my BitmapHelper:

 private void applyWallpaperFromFile(final File file) { Bitmap wallpaperImage = BitmapFactory.decodeFile(file.getPath()); try { if((wallpaperManager.getDesiredMinimumWidth()>0)&&(wallpaperManager.getDesiredMinimumHeight()>0)) { Bitmap blank = BitmapHelper.createNewBitmap(wallpaperManager.getDesiredMinimumWidth(), wallpaperManager.getDesiredMinimumHeight()); Bitmap overlay = BitmapHelper.overlayIntoCentre(blank, wallpaperImage); wallpaperManager.setBitmap(overlay); } else { wallpaperManager.setBitmap(wallpaperImage); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(WallpaperActivity.this,"Wallpaper set to:"+file.getName(), Toast.LENGTH_SHORT).show(); } }); } 
+9
source

Thank you for the article. I found that my wallpaper was stuck at the top of the screen of my device, so I slightly changed the overlayIntoCentre method, replacing 0 in the second drawBitmap call to calculate the height below.

 public static Bitmap overlayIntoCentre(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null);//draw background bitmap //overlay the second in the centre of the first //(may experience issues if the first bitmap is smaller than the second, but then why would you want to overlay a bigger one over a smaller one?!) canvas.drawBitmap(bmp2, (bmp1.getWidth()/2)-(bmp2.getWidth()/2), (bmp1.getHeight()/2)-(bmp2.getHeight/2), null); return bmOverlay; 

}

+3
source

You can take a look at this again: http://developer.android.com/reference/android/app/WallpaperManager.html#suggestDesiredDimensions (int, int)

From the developer's link:

public void suggestDesiredDimensions (int minimumWidth, int minimumHeight)

C: API Level 5 For use only by the current home application, to specify the size of the wallpaper that he would like to use. This allows applications to have virtual wallpapers that are larger than the physical screen, corresponding to the size of their workspace.

Check out developers who don't seem to be reading this. It is for the home to determine what size wallpaper they would like. No one else should call it! Of course, there are no other non-home screen apps that change the wallpaper. It is assumed that these applications will be offered a size so that they can create wallpapers that match it.

+2
source

you can try using suggestDesiredDimensions () method

-one
source

All Articles