Detect screen-touch instances in background on android

非 Y 不嫁゛ 提交于 2021-01-28 04:11:38

问题


I am currently working on a health-based project focusing on a person smartphone usage. And for that i want to monitor his touch-screen usage pattern i.e how long he has been pressing his hands on the screen. When this limit crosses a thresh-hold value will be generated warning to him.

I need to know will i be able to track down a person screen-usage in background (i.e. while he uses all other apps in his phone) If so which functions would help me ??


回答1:


Android does not support this, for privacy and security reasons.

You are welcome to intercept all screen touches, to find out when the user touches the screen. However, then the screen touches will not be available to the underlying apps, and so user will not be able to use the device.

You are welcome to look at implementing an AccessibilityService, to be able to find out about user input in all apps. However, last I checked, this does allow you to find out "how long he has been pressing his hands on the screen".

You are welcome to create a custom Android ROM that bakes in your desired monitoring, then deploy that custom ROM on whatever devices you choose to support. With your own build of Android, you can do pretty much whatever you want, but then you are not making a simple app.

On a rooted device, you can probably run something with superuser privileges to track all user inputs, but I do not have the details about how to do that.




回答2:


So far, there are similar questions asked in here as well. Most commonly, some users suggest defining a window layout stays on the screen as always and capture touch events with onTouch(View v, MotionEvent event) function. But it seems, it is not available anymore (after Android 5.0).

One thing I can suggest that, if the device is rooted, you can execute "su getevent -lt" command and write the output in a BufferReader. That way you can capture the touch events.



来源:https://stackoverflow.com/questions/35540296/detect-screen-touch-instances-in-background-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!