2

I have a wallpaper with optimum size to my phone:

myWallpaper

And I want set it as the homescreen by:

WallpaperManager myWallpaperManager = WallpaperManager.getInstance(this);
String imageFilePath = myWallpaperPath;
Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath);
if (myBitmap != null) {
    try {
        myWallpaperManager.setBitmap(myBitmap);
    } catch (IOException e) {}
} else {}

My problem is that myWallpaper is cropped and then sets as homescreen. I want to set it with full size and quality.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mh m
  • 75
  • 8
  • don't decode your image path, for more info have look [this](https://www.androidhive.info/2014/08/android-building-free-wallpapers-app-part-1/) – Hemant Parmar Aug 31 '18 at 04:57

2 Answers2

1

Add this code on your view click

        GetScreenWidthHeight();

        SetBitmapSize();

        wallpaperManager = WallpaperManager.getInstance(MainActivity.this);

        try {
            wallpaperManager.setBitmap(bitmap2);
            wallpaperManager.suggestDesiredDimensions(width, height);
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
});

public void GetScreenWidthHeight(){

    displayMetrics = new DisplayMetrics();

    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    width = displayMetrics.widthPixels;

    height = displayMetrics.heightPixels;
}

public void SetBitmapSize(){

    bitmap2 = Bitmap.createScaledBitmap(bitmap1, width, height, false);
}

Add the below permissions to your project:

<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>

For a full implementation, check out this link here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sniffer
  • 1,495
  • 2
  • 14
  • 30
0

Try this:

Set the wallpaper to full size like this

Add permissions in your manifest

Manifest file

<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
<uses-permission android:name="android.permission.SET_WALLPAPER"/>

Java file

final WallpaperManager wallpaperManager = (WallpaperManager)getSystemService(
            Context.WALLPAPER_SERVICE);

Bitmap myBitmap = Bitmap.createScaledBitmap(
    Const.cropped_bitmap,
    wallpaperManager.getDesiredMinimumWidth(),
    wallpaperManager.getDesiredMinimumHeight(), 
    true);

wallpaperManager.suggestDesiredDimensions(
    wallpaperManager.getDesiredMinimumWidth(),
    wallpaperManager.getDesiredMinimumHeight());

try {
    wallpaperManager.setBitmap(myBitmap);
    Toast.makeText(CropImageActivity.this,
        CropImageActivity.this.getString(R.string.wallpaper_has_been_set), 0).show();
}
catch (IOException e) {
    e.printStackTrace();
    Toast.makeText(CropImageActivity.this, "Wallpaper not set", 0).show();
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Android Geek
  • 8,956
  • 2
  • 21
  • 35