title: Android App Development: How to get Google Gmail account credentials to send email automatically?
body: <p>I'm trying to create an application that uses a Gmail account to send emails automatically.</p>
  
  <p>I do not want that the user enters username and password if he has already added a Gmail account in his Android Device, but I want the application uses that account to send email automatically.</p>
  
  <p>I already know how to get the username and password but when I ask for the password I get the following error:</p>
  
  <pre><code>02-14 10:53:40.660: E/AndroidRuntime(23719): Caused by: java.lang.SecurityException: caller uid xxxxx is different than the authenticator's uid
  </code></pre>
  
  <p>Where xxxxx is the UID number.
  My code is this:</p>
  
  <pre><code> AccountManager manager = AccountManager.get(this);
   Account[] accounts = manager.getAccountsByType("com.google");
   for (Account account : accounts){
     if(account.name.endsWith("gmail.com")){
        String gmailAddress = account.name;
        String password = manager.getPassword(account);
     }
   }
  </code></pre>
  
  <p>Please give my an example code or a link to read it. Don't give me anything else.
  Many Thaks</p>