Search code examples
androidtouchpressure

Android touch continuous pressure logging


I know that there exist the MotionEvent.getPressure() function which would return some pressure value from the touch screen. However, it only returns the pressure at one given time, for one given event. Is it possible to get the pressure with some sampling rate, i.e. no more motion events are triggered, but we still measure the current pressure?

Thanks!


Solution

  • Depending on your device, Android 4.0ish and later should be upsampling your touches to about 140 events per second. The most recent event you have will have the current pressure. Those pressure readings in MotionEvents originate from the touchscreen driver which is simultaneously reporting changes in coordinates and changes in pressure through the kernel. If you don't get a new event, there is no "new" pressure. Put another way, there is no way to "ask" the touchscreen what the current pressure is, it only produces a stream of events. You may want to look at adb getevent to get a feel for this.

    Make sure you are also reading the historical MotionEvents if you want the most complete touch information possible.