title: Android: AccountManager.getAccounts() returns an empty array
body: <p>I'm writing an app targeted at Lollipop and above. This is my first Android app.</p>
  <p>I'm trying to get a list of all the accounts that are associated with the device. Here is my code:</p>
  <pre class="lang-java prettyprint-override"><code>public void getAllContactsAccounts(Context context){
      AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
      Account[] accounts = accountManager.getAccounts();
      System.out.println(&quot;PrintingAccounts: &quot; + accounts.length);
      for(Account a : accounts){
          System.err.println(&quot;AccountName: &quot; + a.name);
      }
  }
  </code></pre>
  <p>The array from <code>accountManager.getAccounts()</code> ends up having a length of 0, and nothing happens.</p>
  <p>I can't figure out how to fix this. I've added the necessary permissions (plus a few others), no security exception happens, the app runs fine, but it just can't seem to retrieve the accounts.</p>
  <p>Any advice on what I can do here?</p>