自动添加帐户

时间:2011-10-05 17:08:30

标签: android synchronization account accountmanager

我的应用程序需要从服务器同步一些数据。我添加了必要的类(类似于SampleSyncAdapter),现在我可以通过“设置/同步和帐户”添加帐户。 但是我希望在安装应用程序之后已经添加了我的帐户和工作同步(我不希望用户在设置中进行任何手动更改)。怎么做?

3 个答案:

答案 0 :(得分:7)

有点晚了但是......

Account account = new Account("Title", "com.package.nom");
String password = "password";
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(account, password, null);

答案 1 :(得分:1)

您不必添加Evan Elliott发布的以下代码:

Account account = new Account("Title", "com.package.nom");
String password = "password";
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(account, password, null);

以下内容:?

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"
 />

和权限?

答案 2 :(得分:1)

Android AtLeap库包含使用Account Authenticator的帮助程序类。看看它https://github.com/blandware/android-atleap