Setting the Wallpaper from an Image on the SDCard

2019-02-20 13:06发布

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条回答
霸刀☆藐视天下
2楼-- · 2019-02-20 13:46
Bitmap o = BitmapFactory.decodeFile("/sdcard/wallpapers/olive.jpg");

try {
  wallpaperManager.setBitmap(o);
  finish();
} 
catch (IOException e) {
  e.printStackTrace();
}
查看更多
登录 后发表回答