存储更多的数据,Android的客户经理 [英] Store additional data in Android Account Manager

查看:117
本文介绍了存储更多的数据,Android的客户经理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用android AccountManger 同步我的web服务与应用(联系人及压延标准同步)但是,的AccountManager 似乎只存储一个用户名和密码。我的网络服务有三个凭证:用户名,密码和帐号。什么是存储的第三个资料片的最佳做法?

I'd like to use the android AccountManger to sync my webservice and application (standard sync of contacts and calander) however, AccountManager only appears to store a username and password. My web service takes three credentials: a username, a password and an account. What is the best practice for storing the third piece of information?

推荐答案

由于pablisco解释的,可以使用的AccountManager的能力,通过存储任意用户数据的<一个href="http://developer.android.com/reference/android/accounts/AccountManager.html#addAccountExplicitly%28android.accounts.Account,%20java.lang.String,%20android.os.Bundle%29">addAccountExplicitly()'s用户数据包的参数:

As pablisco explained, you can use AccountManager's ability to store arbitrary user data through addAccountExplicitly()'s userData Bundle parameter:

    final Bundle extraData = new Bundle();
    extraData.putString("someKey", "stringData");
    boolean accountCreated = am.addAccountExplicitly(account, password, extraData);

稍后,例如在验证器的<一href="http://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html#getAuthToken%28android.accounts.AccountAuthenticatorResponse,%20android.accounts.Account,%20java.lang.String,%20android.os.Bundle%29">getAuthToken()方法,你可以检索与您正在使用的帐户数据:

Later on, for example in your Authenticator's getAuthToken() method, you can retrieve the data related to the account you are working with:

    String myData = am.getUserData(account, "someKey");

不幸的是在写本书时,你只能检索字符串,所以你的数据应该存储为当您第一次建立绑定字符串。希望这可以帮助别人。

Unfortunately as of this writing you can only retrieve Strings, so your data should be stored as a String when you first build the Bundle. Hope this helps someone.

这篇关于存储更多的数据,Android的客户经理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆