0

I am using UsageStatsManager to get the history of app usage records in a particular day. The problem I have been facing is, for example, when user opens Facebook at 1:00pm, and at 1:01pm, he locks the screen, with facebook still in foreground, and unlocks the screen again at 2:00pm. The app usage API shows history of 1 hour usage of Facbook, whereas I want it to show just 1 minute. Is there any way I can disable the tracking when is the screen is inactive or disable the permission temporily. I am stuck and couldn't find any solution.

4

1 回答 1

0

我认为您可以通过检查您的设备是否被锁定并检查是否有一个简单的技巧来做到这一点 -

KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
 if( myKM.inKeyguardRestrictedInputMode()) {
        //it is locked
    } else {
       //it is not locked
   }

因此,每次您想添加时间时,只需将上述检查放在那里。

于 2018-07-02T04:28:05.207 回答