how to fit the whole image on screen as wallpaper

前端 未结 2 2009
故里飘歌
故里飘歌 2021-01-13 11:24

I am developing an app which picks an image from the gallery and then sets that image as the wallpaper. But here problem is that only part of image is set as wallpaper not t

相关标签:
2条回答
  • 2021-01-13 12:02

    Pass width height to wallpaper manager like this :

    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();
    }
    

    Do not forget to add permission :

    <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    
    0 讨论(0)
  • 2021-01-13 12:25

    Set wallpaper size to your image size:

    WallpaperManager wm = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
    wm.setBitmap(bitmap);
    wm.suggestDesiredDimensions(w, h);
    

    and remember to add permissions:

    <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    
    0 讨论(0)
提交回复
热议问题