2

I'm trying to create an application that uses a Gmail account to send emails automatically.

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.

I already know how to get the username and password but when I ask for the password I get the following error:

02-14 10:53:40.660: E/AndroidRuntime(23719): Caused by: java.lang.SecurityException: caller uid xxxxx is different than the authenticator's uid

Where xxxxx is the UID number. My code is this:

 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);
   }
 }

Please give my an example code or a link to read it. Don't give me anything else. Many Thaks

Animesh
  • 4,926
  • 14
  • 68
  • 110
Meroelyth
  • 5,310
  • 9
  • 42
  • 52

2 Answers2

0

You should include

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

permission to your AndroidManifest.xml

tasomaniac
  • 10,234
  • 6
  • 52
  • 84
0

getting google account credentials is possible only when You share same UID which is not possible when you are writing you are own application.I think You need to use AuthToken that is generated ehen Ever user registers account in the phone.You can exchange Auth token with acesss token in order to send mail automatically..

RanjitRock
  • 1,421
  • 5
  • 20
  • 36