How to detect user interaction of any kind?

时光怂恿深爱的人放手 提交于 2019-12-23 09:54:33

问题


SECURITY ISSUE: I don't now how it happens, but readers of this questions come up with idea that solutions to this problem is a security threat. So please keep in mind, all data I am interested in is measuring time of user in/activity. That's all. What user did -- I am NOT interested at all!


What I need is very simple concept, but I cannot find a solution. I would like to run a process (in the background) and have a listener to user interaction.

So, user touches screen --> my method is triggered.

User unlock phone --> my method is triggered.

User types on physical keyboard --> my method is triggered.

So in short my method is NOT triggered when the phone lies still on the table :-) Please note, that the interaction is with entire phone, not with my app, and I am not interested that user typed letter "K", I am not even interested that user typed something, all I care is the user used the phone in some way.

Btw. the state when user is walking listening to music (phone in the pocket) -- it is NOT interaction.

What I am looking for is a trigger -- something like INTERACTION_DETECTED, or (conversely) a callback method which is set like reportInactiveUser(10*1000) and it would be called if user was inactive for 10 seconds.

QUESTION how to detect user interaction?

Purpose: to measure the time of using manually the phone.

(lack of) PROGRESS

I found out that BatteryStatsImpl could hold the data I need. The instance of it is kept by BatteryStatsService, which however does not let any access to it, only IBatteryStats which in turn has only one interesting method -- getStatistics and the output does not include user activity counters (or they are all zeros; I set all permissions on). So, so far -- bad luck.

All calls have to be made by reflection, because those classes are not available anyway ;-).


回答1:


You want to intercept physical interactions with the phone for that.

For screen touches, this package will come handy. *You can use this to listen for gestures on the screen.

For physical button touches, I suggest you have a look at this.



来源:https://stackoverflow.com/questions/11782501/how-to-detect-user-interaction-of-any-kind

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