这是什么意思的方法是去precated,以及如何解决导致的错误?这是、什么意思、如何解决、错误

2023-09-05 23:35:30 作者:失恋何止33天つ

为什么我得到一个去precation错误上载 setWallpaper(BMP)行了,我该怎么解决这个问题?

  

错误:从类型上下文的方法setWallpaper(位图)是pcated德$ P $

 开关(v.getId()){
 案例R.id.bSetWallpaper:
尝试 {
            getApplicationContext()setWallpaper(BMP)。
        }赶上(IOException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
        打破;
 

解决方案

在东西德precated,这意味着开发者已经创建了这样做的更好的办法,您应该不再使用旧的,或德precated方式。事情是去precated是被遣返的未来。

细思极恐 为学妹解答升学疑惑却没想到对方发来了自己的遗照 恶意P图的背后竟是

在你的情况下,正确的方法,如果你有一个形象的路径设置壁纸如下:

 是=新的FileInputStream(新文件(的ImagePath));
双=新的BufferedInputStream(是);
点阵位图= BitmapFactory.de codeStream(之二);
位图useThisBitmap = Bitmap.createScaledBitmap(
    位图,parent.getWidth(),parent.getHeight(),真);
bitmap.recycle();
如果(的ImagePath!= NULL){
    的System.out.println(我尝试打开位图);
    wallpaperManager = WallpaperManager.getInstance(本);
    wallpaperDrawable = wallpaperManager.getDrawable();
    wallpaperManager.setBitmap(useThisBitmap);
 

如果你有一个形象的URI,然后使用以下命令:

  wallpaperManager = WallpaperManager.getInstance(本);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(的ImagePath);
 

从Maidul的回答这个的问题。

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;

解决方案

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.

 
精彩推荐
图片推荐