arrays - How to add set as wallpaper option in following code in Android -
i creating swipe action in android app. working perfectly. want create set wallpaper option user can set current image wallpaper. add code. not working. please me make current image wallpaper.
code-
public class fullimageactivity extends activity { int position; linearlayout full; button btn; public integer[] mthumbid = { r.drawable.kri1, r.drawable.kri2, r.drawable.kri3, r.drawable.kri4, r.drawable.kri5, r.drawable.kri6, r.drawable.kri7, r.drawable.kri8, r.drawable.kri9 }; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.full_image); // intent data intent = getintent(); // selected image id position = i.getextras().getint("id"); full = (linearlayout) findviewbyid(r.id.full); btn = (button)findviewbyid(r.id.btn); changebackground(); btn.setonclicklistener(new button.onclicklistener(){ @override public void onclick(view arg0) { wallpapermanager mywallpapermanager = wallpapermanager.getinstance(getapplicationcontext()); try { mywallpapermanager.setresource(mthumbid[position]); } catch (ioexception e) { e.printstacktrace(); } }}); activityswipedetector activityswipedetector = new activityswipedetector(this); full.setontouchlistener(activityswipedetector); } private void changebackground(){ full.setbackgroundresource(mthumbid[position]); } public class activityswipedetector implements view.ontouchlistener { static final string logtag = "activityswipedetector"; static final int min_distance = 100; private float downx, upx; activity activity; public activityswipedetector(activity activity){ this.activity = activity; } public void onrighttoleftswipe(){ log.i(logtag, "righttoleftswipe!"); if(position < mthumbid.length - 1){ position++; changebackground(); } } public void onlefttorightswipe(){ log.i(logtag, "lefttorightswipe!"); if(position > 0){ position--; changebackground(); } } public boolean ontouch(view v, motionevent event) { switch(event.getaction()){ case motionevent.action_down: { downx = event.getx(); return true; } case motionevent.action_up: { upx = event.getx(); float deltax = downx - upx; // swipe horizontal? if(math.abs(deltax) > min_distance){ // left or right if(deltax < 0) { this.onlefttorightswipe(); return true; } if(deltax > 0) { this.onrighttoleftswipe(); return true; } } else { log.i(logtag, "swipe " + math.abs(deltax) + " long, need @ least " + min_distance); return false; // don't consume event } return true; } } return false; } }
did declare set wallpaper permission in androidmanifest?
<uses-permission android:name="android.permission.set_wallpaper" />
Comments
Post a Comment