How can i set Wallpaper in android using coding? -
i developing application shows different photos server , user can set selected photos wallpaper of device used given code set wallpaper working image not set not fit screen. used code.
string dirpath = getfilesdir().tostring(); string folder = mphotos.get(nextposition - 1).getcategory(); string filepath = dirpath + "/photoviewer/" + folder + "/" + mphotos.get(nextposition - 1).getfilename(); file imagefile = new file(filepath); bitmap bitmap = bitmapfactory.decodefile(imagefile .getabsolutepath()); wallpapermanager mywallpapermanager = wallpapermanager .getinstance(getapplicationcontext()); try { mywallpapermanager.setbitmap(bitmap); toast.maketext(photoactivity.this, "wallpaper set", toast.length_short).show(); } catch (ioexception e) { toast.maketext(photoactivity.this, "error setting wallpaper", toast.length_short).show(); }
please me out.
to set wallpaper in android use below code: using wallpapermanager class
button buttonsetwallpaper = (button)findviewbyid(r.id.set); imageview imagepreview = (imageview)findviewbyid(r.id.preview); imagepreview.setimageresource(r.drawable.five); buttonsetwallpaper.setonclicklistener(new button.onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub wallpapermanager mywallpapermanager = wallpapermanager.getinstance(getapplicationcontext()); try { mywallpapermanager.setresource(r.drawable.five); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } });
need set permission in manifest:
<uses-permission android:name="android.permission.set_wallpaper"/>
Comments
Post a Comment