Android Lollipop know if app as Usage Stats access -
since android lollipop, have api accessing apps usage stats. however, app must granted permissions user.
i know redirecting user settings using settings.action_usage_access_settings.
now, question how know user has granted permissions can stop redirecting him settings.
thanks!
you can query usagestats daily interval , end time current time , if nothing returned means user hasn’t granted permissions
@targetapi(build.version_codes.lollipop) public boolean doihavepermission(){ final usagestatsmanager usagestatsmanager = (usagestatsmanager) context.getsystemservice(context.usage_stats_service); final list<usagestats> queryusagestats = usagestatsmanager.queryusagestats(usagestatsmanager.interval_daily, 0, system.currenttimemillis()); return !queryusagestats.isempty(); }
daily interval start date 0 , end date current time must @ least return todays usage.so empty if permissions not granted.
Comments
Post a Comment