Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean for a method to be deprecated, and how can I resolve resulting errors?

Why do I get a deprecation error on the line containing setWallpaper(bmp), and how can I resolve it?

Error: The method setWallpaper(Bitmap) from the 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;
like image 332
TAM Avatar asked Mar 03 '13 19:03

TAM


People also ask

What does it mean if a method is deprecated?

A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists.

What to do if a function is deprecated?

Existing code that makes use of deprecated functions is usually okay if left alone, but may require a refactor to make use of newer versions of a library. It is important to point out that "deprecated" does not necessarily mean the function will cease to exist or work in a new version.

What happens when something is deprecated?

In information technology (IT), deprecation means that although something is available or allowed, it is not recommended or that -- in the case where something must be used -- to say it is deprecated means that its failings are recognized.


2 Answers

When something is deprecated, it means the developers have created a better way of doing it and that you should no longer be using the old, or deprecated way. Things that are deprecated are subject to removal in the future.

In your case, the correct way to set the wallpaper if you have an image path 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, then use the following:

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

From Maidul's answer to this question.

like image 153
Zach Latta Avatar answered Sep 23 '22 16:09

Zach Latta


"Deprecated" means that the particular code you are using is no longer the recommended method of achieving that functionality. You should look at the documentation for your given method, and it will more than likely provide a link to the recommended method in it's place.

like image 37
christopher Avatar answered Sep 22 '22 16:09

christopher