title: Check if my application has usage access enabled
body: <p>I'm using the new <code>UsageStatsManager</code> API to <a href="https://stackoverflow.com/a/26885469/444324">get current foreground application</a> in Android 5.0 Lollipop.
  In order to use this API, the user must enable the application in the <code>Settings-&gt;Security-&gt;Apps with usage access</code> screen.</p>
  
  <p>I send the user directly to this screen with this Intent:</p>
  
  <pre><code>
  startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));
  </code></pre>
  
  <p>Now, I want to validate the user enabled my application.
  I wanted to do so like I validate the user enabled my application to use the <code>NotificationListenerService</code> but I have no idea what is the String key, if it even exists.
  <pre><code>
  Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
  // Tried Settings.ACTION_USAGE_ACCESS_SETTINGS as key but it returns null
  </pre></code></p>
  
  <p>Second approach was to query the usage stats and check if it returns results (it returns an empty array when the app is not enabled) and it works most of the times but sometimes it returns 0 results even when my app is enabled.</p>
  
  <pre><code>
  UsageStatsManager mUsageStatsManager = (UsageStatsManager) context.getSystemService("usagestats");
  long time = System.currentTimeMillis();
  List stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 10, time);
  
  if (stats == null || stats.isEmpty()) {
      // Usage access is not enabled
  }
  </code></pre>
  
  <p>Is there a way to check if my application has usage access enabled?</p>