Add account automatically

旧街凉风 提交于 2019-12-29 05:37:45

问题


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?


回答1:


There is Android AtLeap library which contains helper classes to use Account Authenticator. Have a look at it https://github.com/blandware/android-atleap




回答2:


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



回答3:


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?



来源:https://stackoverflow.com/questions/7664987/add-account-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!