I cannot change Android wallpaper using WallpaperManager -


i trying change android wallpaper using code. using wallpapermanager class, no prevail. used .png image in /drawable directory. getting error says, "expected resource of type raw". when run application(when method runs), crashes. must victim of stupid mistake. method changewallpaper() run after user taps button. here code:

 public void changewallpaper(view view) {      try{         wallpapermanager wallpapermanager = wallpapermanager.getinstance(getapplicationcontext());         wallpapermanager.setresource(r.drawable.material_wallpaper);         string successmessage = "wallpaper changes";         toast.maketext(this, successmessage, toast.length_short).show();     } catch (ioexception e) {         e.printstacktrace();         string failedmessage = "operation failed";         toast.maketext(this, failedmessage, toast.length_short).show();     }  } 

edit: there no "raw" folder in /res/ directory.

if want stay drawable, can convert resource bitmap , set wallpaper using setbitmap(bitmap _bitmap) (see wallpapermanager).

wallpapermanager wallpapermanager = wallpapermanager.getinstance(getactivity().getapplicationcontext()); bitmap bitmap = bitmapfactory.decoderesource(getactivity().getresources(), r.drawable.material_wallpaper); wallpapermanager.setbitmap(bitmap); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -