My application needs to synchronize some data from server. I added necessary classes (similarly to SampleSyncAdapter) now I can add account via "Settings/Sync and Accounts". But I want to have already added my account and working synchronization just after application is installed (I do not want user to do any manual changes in settings). How to do this?
Add account automatically
Asked Answered
There is Android AtLeap library which contains helper classes to use Account Authenticator. Have a look at it https://github.com/blandware/android-atleap
A bit late but...
Account account = new Account("Title", "com.package.nom");
String password = "password";
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(account, password, null);
If you follow Ian's suggestion, please consider the following: stuff.mit.edu/afs/sipb/project/android/docs/training/id-auth/… –
Romero
@IanElliott : I am facing same issue like ben75. I tried adding authenticator.xml also. –
Encompass
@Philharmonic : I am facing the same issue, Could you please guide what should be my next step. I tried decrypting my password & added account-authenticator/> also. –
Encompass
@Encompass check this #24227774 –
Philharmonic
Don't you have to add to the following code posted by Evan Elliott :
Account account = new Account("Title", "com.package.nom");
String password = "password";
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(account, password, null);
The following: ?
authenticator.xml
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:icon="@drawable/icon_hdpi"
android:smallIcon="@drawable/icon_hdpi"
android:label="@string/authenticator_label"
/>
and permissions?
do you mean , we need to add this code, permissions and this xml file and then account will be added. I am trying to add account but i am getting error. where should I include this xml file? Do I need to refer to this file in the code? Can you please explain it? :( –
Loraleeloralie
Google won't let you add account from code. the user must do this by himself. I gave up trying to use those methods and used the existing ones. –
Leban
@Li3ro, you think so? How did Whatsapp, Facebook, Linkedin etc did managed this? I'm still searching for the answer btw.. :-) –
Ampere
whatsapp,facebook, linkedin etc are not googles account.. you can programaticly open your own account with the same code –
Leban
There is Android AtLeap library which contains helper classes to use Account Authenticator. Have a look at it https://github.com/blandware/android-atleap
© 2022 - 2024 — McMap. All rights reserved.
java.lang.SecurityException: caller uid 10007 is different than the authenticator's uid
)... see Udinic answer's bellow for a more complete answer. (maybe I miss something, but I really don't understand why this answer is accepted and upvoted ?) – Philharmonic