本文整理汇总了Java中android.accounts.AccountManagerFuture类的典型用法代码示例。如果您正苦于以下问题:Java AccountManagerFuture类的具体用法?Java AccountManagerFuture怎么用?Java AccountManagerFuture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccountManagerFuture类属于android.accounts包,在下文中一共展示了AccountManagerFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthToken
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
mAuthTokenType, mNotifyAuthFailure, null, null);
Bundle result;
try {
result = future.getResult();
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
throw new AuthFailureError(intent);
}
authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
}
if (authToken == null) {
throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
}
return authToken;
}
示例2: getAuthToken
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
public String getAuthToken() throws AuthFailureError {
AccountManagerFuture<Bundle> future = this.mAccountManager.getAuthToken(this.mAccount, this.mAuthTokenType, this.mNotifyAuthFailure, null, null);
try {
Bundle result = (Bundle) future.getResult();
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey("intent")) {
throw new AuthFailureError((Intent) result.getParcelable("intent"));
}
authToken = result.getString("authtoken");
}
if (authToken != null) {
return authToken;
}
throw new AuthFailureError("Got null auth token for type: " + this.mAuthTokenType);
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
}
示例3: addAccount
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
/**
* Asks the user to add an account of a specified type. The authenticator
* for this account type processes this request with the appropriate user
* interface. If the user does elect to create a new account, the account
* name is returned.
* <p>
* <p>This method may be called from any thread, but the returned
* {@link AccountManagerFuture} must not be used on the main thread.
* <p>
*
*/
public AccountManagerFuture<Bundle> addAccount(final int userId, final String accountType,
final String authTokenType, final String[] requiredFeatures,
final Bundle addAccountOptions,
final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
if (accountType == null) throw new IllegalArgumentException("accountType is null");
final Bundle optionsIn = new Bundle();
if (addAccountOptions != null) {
optionsIn.putAll(addAccountOptions);
}
optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, "android");
return new AmsTask(activity, handler, callback) {
@Override
public void doWork() throws RemoteException {
addAccount(userId, mResponse, accountType, authTokenType,
requiredFeatures, activity != null, optionsIn);
}
}.start();
}
示例4: invalidateAuthToken
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
private void invalidateAuthToken(final Account account, String authTokenType) {
final AccountManagerFuture<Bundle> future =
accountManager.getAuthToken(account, authTokenType, null, this, null, null);
new Thread(new Runnable() {
@Override
public void run() {
try {
Bundle bnd = future.getResult();
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
accountManager.invalidateAuthToken(account.type, authtoken);
Log.d("MainActivity", account.name + " invalidated");
} catch (Exception e) {
e.printStackTrace();
showMessage(e.getMessage());
}
}
}).start();
}
示例5: getAuthToken
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
final AccountManager accountManager = AccountManager.get(mContext);
AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount,
mAuthTokenType, mNotifyAuthFailure, null, null);
Bundle result;
try {
result = future.getResult();
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
throw new AuthFailureError(intent);
}
authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
}
if (authToken == null) {
throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
}
return authToken;
}
示例6: removeAccount
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
private void removeAccount(final Account account) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
sharedPreferences.edit().remove("queueName").apply();
ContentResolver.setIsSyncable(account, WEBINSTALL_SYNC_AUTHORITY, 0);
ContentResolver.setSyncAutomatically(account, MyAccountActivity.WEBINSTALL_SYNC_AUTHORITY, false);
if(Build.VERSION.SDK_INT>=8){
ContentResolver.removePeriodicSync(account, MyAccountActivity.WEBINSTALL_SYNC_AUTHORITY, new Bundle());
}
mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() {
@Override
public void run(AccountManagerFuture<Boolean> future) {
addAccount();
finish();
}
}, null);
}
示例7: addAccount
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
private void addAccount() {
mAccountManager.addAccount(Aptoide.getConfiguration().getAccountType(), AptoideConfiguration.AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, null, this, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bnd = future.getResult();
if (bnd.containsKey(AccountManager.KEY_AUTHTOKEN)) {
setContentView(R.layout.form_logout);
} else {
finish();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, null);
}
示例8: addNewAccount
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
private void addNewAccount() {
mAccountManager.addAccount(EnlightnsAccountAuthenticator.ACCOUNT_TYPE,
EnlightnsAccountAuthenticator.AUTH_TOKEN_TYPE, null, null, this, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bnd = future.getResult();
showMessage(getString(R.string.successful_login_toast));
new GetUserRecordsTask().execute();
Log.d(TAG, "AddNewAccount Bundle is " + bnd);
} catch (OperationCanceledException oce) {
Log.d(TAG, "Operation cancelled, no account available, exiting...", oce);
finish();
} catch (Exception e) {
Log.w(TAG, "Exception", e);
showMessage(getString(R.string.login_error));
}
}
}, null);
}
示例9: getAuthToken
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
@Override
public String getAuthToken() throws AuthFailureError {
final AccountManager accountManager = AccountManager.get(mContext);
AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount,
mAuthTokenType, mNotifyAuthFailure, null, null);
Bundle result;
try {
result = future.getResult();
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
throw new AuthFailureError(intent);
}
authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
}
if (authToken == null) {
throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
}
return authToken;
}
示例10: getAuthToken
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
@SuppressWarnings("deprecation") @Override public String getAuthToken()
throws AuthFailureError {
AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType,
mNotifyAuthFailure, null, null);
Bundle result;
try {
result = future.getResult();
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
throw new AuthFailureError(intent);
}
authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
}
if (authToken == null) {
throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
}
return authToken;
}
示例11: removeAccount
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
/**
* Remove account from Android system
*/
@SuppressWarnings("deprecation")
public boolean removeAccount() {
Log.d(getClass().getSimpleName(), "Removing account : " + account.name);
AccountManager accountManager = AccountManager.get(context);
// remove account
AccountManagerFuture accountManagerFuture;
if(android.os.Build.VERSION.SDK_INT < 23) {
accountManagerFuture = accountManager.removeAccount(account, null, null);
} else {
accountManagerFuture = accountManager.removeAccount(account, null, null, null);
}
if (accountManagerFuture.isDone()) {
try {
accountManagerFuture.getResult();
return true;
} catch (Exception e) {
Log.e(getClass().getSimpleName(), "Problem while removing account!", e);
return false;
}
} else {
return false;
}
}
示例12: run
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
@Override
public void run(AccountManagerFuture<Bundle> result) {
try {
Log.d(LOGTAG, "OnGMailTokenAcquired::run() begin");
GMailHandler myHandler = new GMailHandler(getFragmentManager(), ListManager.this);
Bundle bundle = result.getResult();
final String oAuth2Token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
gmailImapReader = new Thread(new GMailImapReader(delayInMillis,
accounts[getAccountIndex()].name, myHandler, oAuth2Token));
gmailImapReader.start();
gmailImapRemover = new Thread(new DeleteEmailViaImap(accounts[getAccountIndex()].name,
oAuth2Token, emailsToBeRemoved));
gmailImapRemover.start();
gmailSmtpWriter = new Thread(new ShareByEmail(accounts[getAccountIndex()].name,
oAuth2Token, emailsToSend));
gmailSmtpWriter.start();
Log.d(LOGTAG, "OnGMailTokenAcquired::run() end");
} catch (Exception e) {
Log.d(LOGTAG, "OnTokenAcquired()", e);
}
}
示例13: run
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
@Override
public void run(AccountManagerFuture<Bundle> result) {
try {
Bundle bundle;
bundle = result.getResult();
Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
if (intent != null) {
this.parent.startActivity(intent);
} else {
this.auth_token = bundle
.getString(AccountManager.KEY_AUTHTOKEN);
this.loginUrl = this.loginUrl + "/_ah/login";
String request = "?continue="
+ URLEncoder.encode("nowhere", "UTF-8") + "&auth="
+ this.auth_token;
URL url = new URL(this.loginUrl);
Runnable runnable = new GetCookieRunnable(this.parent, url,
request, this.localListener);
new Thread(runnable).start();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例14: fetchPioneerAccount
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
private void fetchPioneerAccount() {
String ACCOUNT_TYPE = "com.github.baoti";
String AUTH_TOKEN_TYPE = "pioneer";
accountManager.getAuthTokenByFeatures(ACCOUNT_TYPE, AUTH_TOKEN_TYPE, null,
getView().getActivity(), null, null,
new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle result = future.getResult();
String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
String type = result.getString(AccountManager.KEY_ACCOUNT_TYPE);
String token = result.getString(AccountManager.KEY_AUTHTOKEN);
toaster.show(
String.format("Auth result - name: %s, type: %s, token: %s",
name, type, token));
} catch (Exception e) {
e.printStackTrace();
}
}
}, null);
}
示例15: run
import android.accounts.AccountManagerFuture; //导入依赖的package包/类
public final void run(AccountManagerFuture<Bundle> paramAccountManagerFuture)
{
try
{
if (this.a.i())
{
Intent localIntent = (Intent)((Bundle)paramAccountManagerFuture.getResult()).getParcelable("intent");
gkl localgkl = this.b;
bw localbw = this.a.h();
gko localgko = (gko)localbw.a("new.account.launcher");
if (localgko == null)
{
localgko = new gko();
localbw.a().a(localgko, "new.account.launcher").c();
}
gkn localgkn = new gkn(localgkl, localgko, localIntent);
efj.m().post(localgkn);
}
return;
}
catch (Exception localException)
{
throw new IllegalStateException(localException);
}
}