List of usage examples for android.accounts AccountManager getUserData
public String getUserData(final Account account, final String key)
From source file:com.ntsync.android.sync.shared.SyncUtils.java
/** * Get Restrictions//w w w . java 2s.c o m * * @param account * the account we're syncing * @return null if restrictions were never saved before. */ public static Restrictions getRestrictions(Account account, AccountManager accountManager) { boolean photoSupport = false; int maxContacts = Integer.MAX_VALUE; int maxGroups = Integer.MAX_VALUE; Date validUntil = null; boolean foundRestr = false; String photoSupportStr = accountManager.getUserData(account, SYNC_RESTRICTIONS_PHOTOSUPPORT); if (!TextUtils.isEmpty(photoSupportStr)) { photoSupport = Boolean.parseBoolean(photoSupportStr); foundRestr = true; } String maxContactStr = accountManager.getUserData(account, SYNC_RESTRICTIONS_MAXCONTACTS); if (!TextUtils.isEmpty(maxContactStr)) { maxContacts = Integer.parseInt(maxContactStr); foundRestr = true; } String maxGroupStr = accountManager.getUserData(account, SYNC_RESTRICTIONS_MAXGROUPS); if (!TextUtils.isEmpty(maxGroupStr)) { maxGroups = Integer.parseInt(maxGroupStr); foundRestr = true; } String validUntilStr = accountManager.getUserData(account, SYNC_RESTRICTIONS_VALIDUNTIL); if (!TextUtils.isEmpty(validUntilStr)) { validUntil = new Date(Long.parseLong(validUntilStr)); } Restrictions restr = null; if (foundRestr) { restr = new Restrictions(maxContacts, maxGroups, photoSupport, validUntil); } return restr; }
From source file:com.murrayc.galaxyzoo.app.LoginUtils.java
/** * Get a preference from the Account./* w w w . ja va 2 s.c om*/ * * Don't call this from the main thread - use an AsyncTask, for instance. * * @param context * @param prefKeyResId * @return */ @Nullable private static String getStringPref(final Context context, final int prefKeyResId) { final AccountManager mgr = AccountManager.get(context); final Account account = getAccount(context); if (account == null) { return null; } //Note that this requires the AUTHENTICATE_ACCOUNTS permission on //SDK <=22. return mgr.getUserData(account, context.getString(prefKeyResId)); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
public static String sendMessageToServer(final Context ctx, final String path, final Long toId, final String toType, final Long timelineId, boolean retry, Long localId, String messageBody, Object messageApp) {/*from w ww. j a v a 2 s .c o m*/ Account account = AccountUtils.getAccount(ctx.getApplicationContext(), true); AccountManager am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE); MessageSend m = new MessageSend(); m.setBody(messageBody); m.setFrom(Long.valueOf(am.getUserData(account, JsonKeys.ID_STORED))); m.setTo(toId); m.setLocalId(localId); if (messageApp != null) m.setApp(messageApp); CommandStoreService cs = new CommandStoreService(ctx.getApplicationContext()); try { boolean result = false; if (toType.equals(JsonKeys.GROUP)) { result = cs.createCommand(JsonParser.MessageSendToJson(m), Command.METHOD_SEND_MESSAGE_TO_GROUP, path); } else if (toType.equals(JsonKeys.USER)) { result = cs.createCommand(JsonParser.MessageSendToJson(m), Command.METHOD_SEND_MESSAGE_TO_USER, path); } if (result) { return ConstantKeys.SENDING_OK; } else { return ConstantKeys.SENDING_OFFLINE; } } catch (JSONException e) { log.error("Cannot create command", e); return ConstantKeys.SENDING_FAIL; } }
From source file:com.xiaomi.account.utils.SysHelper.java
public static boolean uploadInfoToServer(Context context, HashMap<String, Object> uploadInfo, int uploadType, String sid) throws InvalidResponseException, CipherException, IOException, AuthenticationFailureException, AccessDeniedException { Account account = ExtraAccountManager.getXiaomiAccount(context); if (account == null) { Log.w(TAG, "no Xiaomi account"); return false; }/*w w w . j a v a2 s . com*/ AccountManager am = AccountManager.get(context); ExtendedAuthToken extToken = ExtendedAuthToken.parse(getAuthToken(am, account, sid)); if (extToken == null) { Log.d(TAG, "uploadInfoToServer extToken is null"); return false; } String serviceToken = extToken.authToken; String security = extToken.security; String encryptedUserId = am.getUserData(account, Constants.KEY_ENCRYPTED_USER_ID); switch (uploadType) { case LicenseActivity.PRIVACY_POLICY /*0*/: return CloudHelper.uploadDeviceInfo(account.name, encryptedUserId, serviceToken, security, uploadInfo); case SdkReturnCode.LOW_SDK_VERSION /*1*/: return CloudHelper.uploadXiaomiUserInfo(account.name, encryptedUserId, serviceToken, security, uploadInfo); default: return false; } }
From source file:com.ntsync.android.sync.client.NetworkUtilities.java
/** * /* w ww . j av a2s . c o m*/ * @param accountManager * @param account * @return null if client has not yet a clientId */ private static String getClientId(AccountManager accountManager, Account account) { String clientIdString = accountManager.getUserData(account, SYNC_CIENTID_KEY); if (!TextUtils.isEmpty(clientIdString)) { return clientIdString; } return null; }
From source file:com.zoterodroid.syncadapter.CitationSyncAdapter.java
private void InsertCitations(Account account, SyncResult syncResult) throws AuthenticationException, IOException { AccountManager am = AccountManager.get(mContext); String userid = am.getUserData(account, Constants.PREFS_AUTH_USER_ID); Log.d("userid", userid); String username = account.name; ArrayList<Citation> addCitationList = new ArrayList<Citation>(); Log.d("CitationSync", "In Citation Load"); addCitationList = ZoteroApi.getAllCitations(null, account, userid, mContext); if (!addCitationList.isEmpty()) { for (Citation b : addCitationList) { CitationManager.AddCitation(b, username, mContext); }/*from ww w. j av a 2 s. c om*/ } }
From source file:com.xiaomi.account.utils.SysHelper.java
public static HashMap<String, String> querySnsInfoFromServer(Context context, Account account) { if (account == null) { Log.w(TAG, "no Xiaomi account, skip to querySnsInfoFromServer"); return null; }//from w w w . ja v a 2s . c om String userId = account.name; AccountManager am = AccountManager.get(context); int count = 0; while (count < 2) { String authToken = getAuthToken(am, account, Constants.PASSPORT_API_SID); ExtendedAuthToken extendedAuthToken = ExtendedAuthToken.parse(authToken); if (extendedAuthToken != null) { String serviceToken = extendedAuthToken.authToken; String security = extendedAuthToken.security; if (serviceToken == null || security == null) { break; } String encryptedUserId = am.getUserData(account, Constants.KEY_ENCRYPTED_USER_ID); try { HashMap<String, String> data = Maps.newHashMap(); data.put(com.xiaomi.account.Constants.EXTRA_SINA_WEIBO_ACCESSTOKEN, CloudHelper.getBindedAccessToken(userId, encryptedUserId, com.xiaomi.account.Constants.SINA_WEIBO_SNS_TYPE, serviceToken, security)); data.put(com.xiaomi.account.Constants.EXTRA_QQ_ACCESSTOKEN, CloudHelper.getBindedAccessToken(userId, encryptedUserId, com.xiaomi.account.Constants.QQ_SNS_TYPE, serviceToken, security)); if (!Build.IS_INTERNATIONAL_BUILD) { return data; } data.put(com.xiaomi.account.Constants.EXTRA_FACEBOOK_ACCESSTOKEN, CloudHelper.getBindedAccessToken(userId, encryptedUserId, com.xiaomi.account.Constants.FACEBOOK_SNS_TYPE, serviceToken, security)); return data; } catch (InvalidResponseException e) { Log.e(TAG, "invalid response when get user info", e); } catch (CipherException e2) { Log.e(TAG, "CipherException when get user info", e2); } catch (IOException e3) { Log.e(TAG, "IOException when get user info", e3); } catch (AuthenticationFailureException e4) { Log.e(TAG, "auth failure when get user info", e4); am.invalidateAuthToken(account.type, authToken); count++; } catch (AccessDeniedException e5) { Log.e(TAG, "access denied when get user info", e5); } } else { break; } } return null; }
From source file:com.digitalarx.android.syncadapter.ContactSyncAdapter.java
private String getAddressBookUri() { if (mAddrBookUri != null) return mAddrBookUri; AccountManager am = getAccountManager(); @SuppressWarnings("deprecation") String uri = am.getUserData(getAccount(), Constants.KEY_OC_URL).replace(AccountUtils.WEBDAV_PATH_2_0, AccountUtils.CARDDAV_PATH_2_0); uri += "/addressbooks/" + getAccount().name.substring(0, getAccount().name.lastIndexOf('@')) + "/default/"; mAddrBookUri = uri;//from w w w .ja va 2s . c o m return uri; }
From source file:liqui.droid.activity.SyncStatListCached.java
@Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { AccountManager am = AccountManager.get(getApplicationContext()); String name = am.getUserData(mAccount, Constants.Account.API_NAME); String memberId = am.getUserData(mAccount, Constants.Account.MEMBER_ID); Uri uri = DBProvider.SYNC_RUN_CONTENT_URI.buildUpon().appendQueryParameter("db", memberId + "@" + name) .build();//from ww w . j a v a 2 s .co m // Log.d("XXX", "Uri " + uri); return new CursorLoader(getApplication(), uri, null, null, null, "_id DESC"); }
From source file:com.cerema.cloud2.operations.UpdateOCVersionOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { AccountManager accountMngr = AccountManager.get(mContext); String statUrl = accountMngr.getUserData(mAccount, Constants.KEY_OC_BASE_URL); statUrl += AccountUtils.STATUS_PATH; RemoteOperationResult result = null; GetMethod get = null;/* www . ja v a2 s .c o m*/ try { get = new GetMethod(statUrl); int status = client.executeMethod(get); if (status != HttpStatus.SC_OK) { client.exhaustResponse(get.getResponseBodyAsStream()); result = new RemoteOperationResult(false, status, get.getResponseHeaders()); } else { String response = get.getResponseBodyAsString(); if (response != null) { JSONObject json = new JSONObject(response); if (json != null && json.getString("version") != null) { String version = json.getString("version"); mOwnCloudVersion = new OwnCloudVersion(version); if (mOwnCloudVersion.isVersionValid()) { accountMngr.setUserData(mAccount, Constants.KEY_OC_VERSION, mOwnCloudVersion.getVersion()); Log_OC.d(TAG, "Got new OC version " + mOwnCloudVersion.toString()); result = new RemoteOperationResult(ResultCode.OK); } else { Log_OC.w(TAG, "Invalid version number received from server: " + json.getString("version")); result = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); } } } if (result == null) { result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } } Log_OC.i(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage()); } catch (JSONException e) { result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e); } finally { if (get != null) get.releaseConnection(); } return result; }