0

My wallpaper application's wallpapers doesn't fit for all devices. Images are 1080x1920px and in some devices, wallpapers are overflows and crops automatically.

Here is the code that I use to set wallpaper;

img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WallpaperManager wallmgr = WallpaperManager.getInstance(getApplicationContext());
                try{
                    wallmgr.setResource(+ R.drawable.a1);
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
        });

What can I do to fit images ?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Tolga Dogan
  • 45
  • 1
  • 5

1 Answers1

0
DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels; 
int width = metrics.widthPixels;
Bitmap tempbitMap = BitmapFactory.decodeResource(getResources(), R.drawable.img);
Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap,width,height, true);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this); 
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(width, height);
try {
    wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
    e.printStackTrace();
}

Question was answered really long ago if i am not mistaking?

android wallpapermanager fit screen

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
djevtic
  • 68
  • 5