Java – what does it mean for deprecated methods and how to resolve the resulting errors?
•
Java
Why do I have a deprecation error on the line containing setwallpaper (BMP), and how to solve it?
switch(v.getId()){ case R.id.bSetWallpaper: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break;
Solution
When something is discarded, it means that developers have created a better method, and you should no longer use the old or discarded way What is discarded will be deleted in the future
In your case, if you have an image path, the correct way to set the wallpaper 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);
Answer this question from maidul
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码