Setting the Wallpaper from an Image on the SDCard

爷,独闯天下 提交于 2019-12-01 10:16:09

问题


How would one go about setting the homescreen wallpaper from an image on the SDcard?

i.e.:

try {
    wallpaperManager.setResource("/sdcard/wallpaper/olive.jpg");
    finish();
} catch(IOException e) {
    e.printStackTrace();
} 

hasn't worked, returned an error: 'The method setResource(int) in the type WallpaperManager is not applicable for the arguments (String)'


回答1:


Bitmap o = BitmapFactory.decodeFile("/sdcard/wallpapers/olive.jpg");

try {
  wallpaperManager.setBitmap(o);
  finish();
} 
catch (IOException e) {
  e.printStackTrace();
}


来源:https://stackoverflow.com/questions/3208708/setting-the-wallpaper-from-an-image-on-the-sdcard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!