MrRobot9
MrRobot9

Reputation: 2684

disable app usage tracking temporily

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.

Upvotes: 0

Views: 206

Answers (1)

Ashutosh Sagar
Ashutosh Sagar

Reputation: 1009

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.

Upvotes: 0

Related Questions