What does it mean that the method is out of date, and how can I resolve errors that occur?

Why am I getting an outdated error on a line containing setWallpaper(bmp) , and how to resolve it?

Error: the setWallpaper (Bitmap) method of type Context is deprecated

 switch(v.getId()){ case R.id.bSetWallpaper: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; 
+6
source share
4 answers

When something is out of date, it means that the developers have created a better way to do this and that you should no longer use the old or obsolete method. Items that are out of date are subject to disposal in the future.

In your case, the correct way to set the wallpaper, if you have a path to the image, is as follows:

 is = new FileInputStream(new File(imagePath)); bis = new BufferedInputStream(is); Bitmap bitmap = BitmapFactory.decodeStream(bis); Bitmap useThisBitmap = Bitmap.createScaledBitmap( bitmap, parent.getWidth(), parent.getHeight(), true); bitmap.recycle(); if(imagePath!=null){ System.out.println("Hi I am try to open Bit map"); wallpaperManager = WallpaperManager.getInstance(this); wallpaperDrawable = wallpaperManager.getDrawable(); wallpaperManager.setBitmap(useThisBitmap); 

If you have an image URI, use the following:

 wallpaperManager = WallpaperManager.getInstance(this); wallpaperDrawable = wallpaperManager.getDrawable(); mImageView.setImageURI(imagepath); 

From Maidul, answer this question.

+11
source

"Deprecated" means that the specific code you are using is no longer the recommended method to achieve this functionality. You should look at the documentation for this method and, most likely, provide a link to the recommended method in this place.

+5
source
 WallpaperManager myWallpaperManager=WallpaperManager.getInstance(getApplicationContext()); try { myWallpaperManager.setBitmap(bmp); } catch (IOException e) { Toast.makeText(YourActivity.this, "Ooops, couldn't set the wallpaper", Toast.LENGTH_LONG).show(); } 
+3
source

You should use WallpaperManager.setStream () instead of Context.setWallpaper () as it is deprecated and can be removed in newer versions of the API.

+1
source

All Articles