android - how to fit the whole image on screen as wallpaper -


I am developing an app that chooses an image from the gallery and then sets that image as wallpaper but The problem here is that only one part of the image is not a complete image in the form of a wallpaper, but I want to set the whole image as a wallpaper. Can you please tell me how it can be done?

This is my code ...

  The public class extends scaleimage activity first created * / public vs. creature (bundle saved instenstate) {super. Contents (Saved Instantstate); SetContentView (R.layout.main); String filename; File file = new file ("/ sdcard / picture"); File [] imageFiles = file.listFiles (); If (imageFiles.length & gt; 0) {FileName = imageFiles [0] .getName (); Ultimate WallpaperManager WallpaperManager = WallpaperManager.Testense (getBaseContext ()); Bitmap myBitmap = BitmapFactory.decodeFile ("/ sdcard / picture" + "/" + filename); DisplayMetrics displayMetrics = new display metric (); . GetWindowManager () getDefaultDisplay () getMetrics (displayMetrics). Int height = displayMetrics.heightPixels; Int width = displayMetrics.widthPixels & lt; & Lt; 1; MyBitmap = Bitmap.Sant ScalchedBitmap (Merrymatemap, width, height, true); Try {wallpaperManager.setBitmap (myBitmap); } Grip (Exception E) {// TODO Auto generated blocking block e.printStackTrace (); }}}}    

Set wallpaper size to your image size:

  WallpaperManager wm = (wallpaper manager) getSystemService (WALLPAPER_SERVICE); Wm.setBitmap (bitmap); Wm.suggestDesiredDimensions (W, H);   

Remember to add more permissions:

  & lt; Usage-permission Android: name = "android.permission.SET_WALLPAPER_HINTS" /> & Lt; Usage-permission Android: name = "android.permission.SET_WALLPAPER" />    

Comments