detect weather user has swiped left or right on screen on outside of activity in android -


i want check weather user has swiped left or right on outside app.i know can done ontouchevent() setting windowmanager don't know how had gone through various websites , link didn't found proper solution this.please me.

i have used code detect swipes inside activity only,it doesn't detect swipes outside app

 public class swipe implements view.ontouchlistener {      private  gesturedetector gesturedetector;     int swipe_threshold=200;     int swipe_velocity_threshold=200;        public swipe(context context){         gesturedetector=new gesturedetector(context,new customgesturelistenerclass());     }         @override     public boolean ontouch(view v, motionevent event) {         return gesturedetector.ontouchevent(event);     }      private final class customgesturelistenerclass extends gesturedetector.simpleongesturelistener{          @override         public boolean ondown(motionevent event){             return false;         }          @override         public boolean onfling(motionevent startmotionevent,motionevent endmotionevent,float velocityx,float velocityy)        {            boolean result=false;            try{                float diffy=endmotionevent.gety()-startmotionevent.gety();                float diffx=endmotionevent.getx()-startmotionevent.getx();                 if(math.abs(diffx)>math.abs(diffy)){                    if(math.abs(diffx)>swipe_threshold&&math.abs(velocityx)>swipe_velocity_threshold){                        if(diffx>0){                            log.i("swipe","right swipe");                        }                        else{                            log.i("swipe","left swipe");                        }                    }                    result=true;                }                result=true;            }            catch (exception e){                e.printstacktrace();            }            return result;        }     }   } 


Comments