日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 帐户管理,Android开发之帐户管理

發布時間:2024/9/27 Android 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 帐户管理,Android开发之帐户管理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

android.accounts主要包括了集中式的帳戶管理API,

AccountManagerCallback,

AccountManagerFuture,

OnAccountsUpdateListener,

AbstractAccountAuthenticator,

Account,

AccountAuthenticatorActivity,

AccountAuthenticatorResponse,

AccountManager,

AuthenticatorDescription,

示例學習:添加多個帳戶來集中管理

1. 在AndroidManifest.xml文件中授權,以及確定API lever為5,

2.在Activity中,得到AccountManager對象

AccountManager accountManager = AccountManager.get(this);

AccountManager中的常用方法

addAccount,

addOnAccountsUpdatedListener,

removeOnAccountsUpdatedListener,

clearPassword,

getAccounts,

getAccountsByType,

getPassword,

getUserData,

setPassword,

removeAccount,

將指定類型的帳戶信息全部列出來

Account[] accounts = accountManager.getAccountsByType(xxx);

for(Account account : accounts) {

String name = account.name;

String type = account.type;

}

如何將帳戶信息添加到帳戶管理器中

Activity self = this;

String server, username, password, type;

Account account = new Account(name, type);

Bundle userdata = new Bundle();

userdata.putString(“server”, server);

AccountManager am = AccountManager.get(self);

// 向帳戶管理器中添加一個帳戶

if(am.addAccountExplicitly(account, password, userdata)) {

Bundle result = new Bundle();

result.putString(AccountManager.KEY_ACCOUNT_NAME, username);

result.putString(AccountManager.KEY_ACCOUNT_TYPE, type);

setAccountAuthenticatorResult(result);

}

// 添加一個帳戶服務(Service)和一個驗證器(AbstractAccountAuthenticator)

1. 構建res/xml/authenticator.xml

android:accountType=”com.txrj.AccountType”

android:icon=”@drawable/icon”

android:smallIcon=”@drawable/icon”

android:label=”@string/account_label”

android:accountPreferences=”@xml/account_preferences”

/>

2. 在AndroidManifest.xml文件中開啟一個帳戶管理服務

android:resource=”@xml/authenticator” />

3. 實現帳戶服務類SleepyAccountsService

public class SleepyAccountsService extends Service {

private SleepyAccountAuthenticator authenticator;

public Ibinder onBind(Intent intent) {

if(intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) {

return getSleepyAuthenticator().getIBinder();

return null;

}

private SleepyAccountAuthenticator getSleepyAuthenticator() {

if(authenticator == null)

authenticator = new SleepyAccountAuthenticator(this);

return authenticator;

}

}

}

4. 在添加、操作帳戶時會通過AbstractAccountAuthenticator實現異步調用。

public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,

String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException

{

Bundle bundle = new Bundle();

Intent intent = new Intent(context, SleepyAccountAuthenticatorActivity.class);;

intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

bundle.putParcelable(AccountManager.KEY_INTENT, intent);

return bundle;

}

總結

以上是生活随笔為你收集整理的android 帐户管理,Android开发之帐户管理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。