Android service listen to touch event

machinery

I would like to collect touch input (position and pressure) in an Android 5.1 application. This is possible with an onTouchListener binded to a specific view. But I would like to collect the touch events in a service (running in the background) and not bound to a specific view.

Is it somehow possible to collect touch events in a service?

Ekalips

Basically - yes. You can pass any View into your Service and add touch event listener there. But with this you can face serious memory leak problems, because with Viewyou'll pass Activity of Fragment Context. Maybe it can work with some ServiceConnection and managing onCreate/onDestroy (activity/fragment lifecycle).

But! Really better approach will be overriding Activity and then inherit from it all your other activities. There you'll have slightly reduced chance of memory leak. You can try to add onTouchEvent listener to activity decor view and receive touch events for whole screen. Or even add some invisible view in front of all views and track touches there (I'm not sure if DecorView variant will work). And then pass touches wherever you want.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android listen to touch release

From Dev

Android is it possible to create a service overlay and intercept all touch event data?

From Dev

Android inject touch event

From Dev

Android: Send a touch event

From Dev

Android inject touch event

From Dev

Android: Send a touch event

From Dev

Android move view on touch event

From Dev

Android - "Faking" a touch event not working

From Dev

Touch or Click event ViewPagerIndicator in Android

From Dev

Android - "Faking" a touch event not working

From Dev

Android Studio : ListView On Touch Event

From Dev

Android listen for ACTION_DOCK_EVENT

From Dev

Android - Send touch event to other views

From Dev

How to programmatically trigger the touch event in android?

From Dev

Handle touch event for items inside Recyclerview - android

From Dev

How to make the touch event in openstreetmap android

From Dev

Android Nested ViewPager Disable Touch Event

From Dev

Detecting touch event on Android devices with different density

From Dev

How to stop touch event for desired time in android?

From Dev

properly handling multi-touch event android

From Dev

Android animation build cube tower on touch event

From Dev

How to programmatically trigger the touch event in android?

From Dev

Android : Update Image in GridView on touch event in Adapter

From Dev

Simulating touch event in a certain interval in android

From Dev

Android Nested ViewPager Disable Touch Event

From Dev

How to stop touch event for desired time in android?

From Dev

Generating touch events from a background service in android

From Dev

Listen to Queue (Event Driven no polling) Service-Bus / Storage Queue

From Dev

Detect touch event of navigation buttons inside a service having window

Related Related

  1. 1

    Android listen to touch release

  2. 2

    Android is it possible to create a service overlay and intercept all touch event data?

  3. 3

    Android inject touch event

  4. 4

    Android: Send a touch event

  5. 5

    Android inject touch event

  6. 6

    Android: Send a touch event

  7. 7

    Android move view on touch event

  8. 8

    Android - "Faking" a touch event not working

  9. 9

    Touch or Click event ViewPagerIndicator in Android

  10. 10

    Android - "Faking" a touch event not working

  11. 11

    Android Studio : ListView On Touch Event

  12. 12

    Android listen for ACTION_DOCK_EVENT

  13. 13

    Android - Send touch event to other views

  14. 14

    How to programmatically trigger the touch event in android?

  15. 15

    Handle touch event for items inside Recyclerview - android

  16. 16

    How to make the touch event in openstreetmap android

  17. 17

    Android Nested ViewPager Disable Touch Event

  18. 18

    Detecting touch event on Android devices with different density

  19. 19

    How to stop touch event for desired time in android?

  20. 20

    properly handling multi-touch event android

  21. 21

    Android animation build cube tower on touch event

  22. 22

    How to programmatically trigger the touch event in android?

  23. 23

    Android : Update Image in GridView on touch event in Adapter

  24. 24

    Simulating touch event in a certain interval in android

  25. 25

    Android Nested ViewPager Disable Touch Event

  26. 26

    How to stop touch event for desired time in android?

  27. 27

    Generating touch events from a background service in android

  28. 28

    Listen to Queue (Event Driven no polling) Service-Bus / Storage Queue

  29. 29

    Detect touch event of navigation buttons inside a service having window

HotTag

Archive