Wallpaper not properly fit on device screen

后端 未结 5 521
我寻月下人不归
我寻月下人不归 2020-11-29 08:07

I have one set of images in one drawable folder. I have one button to set image as wallpaper on device screen. But when I set this image as wallpaper its either zoom or crop

5条回答
  •  感情败类
    2020-11-29 08:17

    Try this code:

    public void changeWallpaper(String path) {
            FileInputStream is;
            BufferedInputStream bis;
            WallpaperManager wallpaperManager;
            Drawable wallpaperDrawable;
            File sdcard = Environment.getExternalStorageDirectory();
            try {
                is = new FileInputStream(new File(path));
                bis = new BufferedInputStream(is);
                Bitmap bitmap = BitmapFactory.decodeStream(bis);
                Bitmap useThisBitmap = Bitmap.createBitmap(bitmap);
                wallpaperManager = WallpaperManager.getInstance(getActivity());
                wallpaperDrawable = wallpaperManager.getDrawable();
                wallpaperManager.setBitmap(useThisBitmap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

    In this example , I have used image from my device SD card...

    It's perfectly worked for me..

提交回复
热议问题