3

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

4

3 回答 3

7

有点晚了,但是...

Account account = new Account("Title", "com.package.nom");
String password = "password";
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(account, password, null);
于 2011-11-04T08:31:34.503 回答
1

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

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

以下: ?

身份验证器.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"
 />

和权限?

于 2012-03-26T08:13:38.550 回答
1

有一个 Android AtLeap 库,其中包含使用 Account Authenticator 的帮助类。看看它https://github.com/blandware/android-atleap

于 2014-03-29T19:03:11.300 回答