1

i am trying to do something silmiar to apps like swipepad, taskxp, and taskie where the user swipes
or touches an area of the phone screen like the edges and the program functions even if its activity is not shown.

I have no idea where to start since i dont even know whats its called

Any help would be much appreciated!

kevdliu
  • 1,709
  • 4
  • 29
  • 46
  • 1
    Maybe the response comes a little late, but I'm using a workaround for this here http://stackoverflow.com/a/21271833/2510749 and I would like your comments to see how it can be improved. – Junior Buckeridge Jan 22 '14 at 00:24

1 Answers1

2

Here's the answer to a similar question Get co-ordinates touch screen in a background service:

No, sorry. Your activities can pass information about touch events to a service, but a service cannot directly receive touch events

But you can only receive touch events with an activity running.

Here's how you would do a touch listener in an activity:

ImageView playLayout = (ImageView)findViewById(R.id.playLayout);
    playLayout.setKeepScreenOn(true);

    playLayout.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent me) {
            float newY = me.getY();
            float newX = me.getX();
            int action = me.getAction();

            if (action==0){
                Log.v(tag, "New Touch");
                Log.i(tag, String.valueOf("Action " + action +
                        " happened at X,Y: " + "("+newX+","+newY + ")"));
            }
            return true;
        }
    });     

Of course you can add more to it. There, I'm just logging the x and y coordinates of where the touch happened.

Community
  • 1
  • 1
Reed
  • 14,703
  • 8
  • 66
  • 110
  • Jakar has pointed you to correct answer. If you've seen an application that does achieve this effect they are not using anything in the public API to make it happen, and it is very likely(and hopefully) that whatever system exploit they are using gets fixed ASAP. Which will break their (and yours if you happen to find out how they did it) applications – FoamyGuy Sep 01 '11 at 21:04
  • Too late to comment but a service can directly recieve touch event through windowmanager as mentioned by @junior buckeridge in the comment section of the question – therealprashant Dec 14 '14 at 07:37