简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM