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.

MrRobot9
  • 2,402
  • 4
  • 31
  • 68

1 Answers1

0

I think you can do it by checking whether your device is locked or not and to check that there is a simple trick -

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

So everytime you like to add time just put the above check there.

Ashutosh Sagar
  • 981
  • 8
  • 20