java – 对于不推荐使用的方法意味着什么,以及如何解决产生的错误?
发布时间:2020-05-25 15:42:52 所属栏目:Java 来源:互联网
导读:为什么我在包含setWallpaper(bmp)的行上出现弃用错误,如何解决? Error: The method setWallpaper(Bitmap) from the type Context is deprecated switch(v.getId()){ case R.id.bSetWallpaper:try { getApplicationContext(
|
为什么我在包含setWallpaper(bmp)的行上出现弃用错误,如何解决?
switch(v.getId()){
case R.id.bSetWallpaper:
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
解决方法当某些东西被弃用时,这意味着开发人员已经创建了一种更好的方法,并且您不应再使用旧的或弃用的方式.被弃用的东西将来会被删除.在您的情况下,如果您有图像路径,设置壁纸的正确方法如下: 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);
如果您有图像URI,请使用以下内容: wallpaperManager = WallpaperManager.getInstance(this); wallpaperDrawable = wallpaperManager.getDrawable(); mImageView.setImageURI(imagepath); 从Maidul回答this问题. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
