这是什么意思的方法是去precated,以及如何解决导致的错误? [英] What does it mean for a method to be deprecated, and how can I resolve resulting errors?

查看:356
本文介绍了这是什么意思的方法是去precated,以及如何解决导致的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  

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

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

解决方案

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

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

 是=新的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.

这篇关于这是什么意思的方法是去precated,以及如何解决导致的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆