List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:com.manning.androidhacks.hack023.service.TodoSyncAdapter.java
public TodoSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); mContentResolver = context.getContentResolver(); mAccountManager = AccountManager.get(context); }
From source file:at.bitfire.davdroid.mirakel.syncadapter.DavSyncAdapter.java
public DavSyncAdapter(Context context) { super(context, true); synchronized (this) { if (androidID == null) androidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); }/* w ww . java2 s. com*/ accountManager = AccountManager.get(context); }
From source file:com.ntsync.android.sync.shared.SyncUtils.java
public static void removePeriodicSync(String authority, Bundle extras, Context context) { AccountManager am = AccountManager.get(context); Account[] accounts = am.getAccountsByType(Constants.ACCOUNT_TYPE); for (Account ac : accounts) { ContentResolver.removePeriodicSync(ac, authority, extras); }//from w w w .j a v a 2s. com }
From source file:com.num.mobiperf.AccountSelector.java
/** * Return the list of account names for users to select *///from w w w . j a v a 2 s .co m public static String[] getAccountList(Context context) { AccountManager accountManager = AccountManager.get(context.getApplicationContext()); Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE); int numAccounts = accounts == null ? 1 : accounts.length + 1; String[] accountNames = new String[numAccounts]; for (int i = 0; i < accounts.length; i++) { accountNames[i] = accounts[i].name; } accountNames[numAccounts - 1] = "Anonymous"; return accountNames; }
From source file:com.friedran.appengine.dashboard.client.AppEngineDashboardAuthenticator.java
public void executeAuthentication() { // Gets the auth token asynchronously, calling the callback with its result (uses the // deprecated API which is the only one supported from API level 5). AccountManager.get(mApplicationContext).getAuthToken(mAccount, AUTH_TOKEN_TYPE, false, new AccountManagerCallback<Bundle>() { public void run(AccountManagerFuture result) { Bundle bundle;/* w ww .jav a 2s . c o m*/ try { LogUtils.i("AppEngineDashboardAuthenticator", "GetAuthTokenCallback.onPostExecute started..."); bundle = (Bundle) result.getResult(); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required LogUtils.i("AppEngineDashboardAuthenticator", "User input is required..."); mOnUserInputRequiredCallback.onUserInputRequired(intent); } else { LogUtils.i("AppEngineDashboardAuthenticator", "Authenticated, getting auth token..."); onGetAuthToken(bundle); } } catch (Exception e) { // Can happen because of various like connectivity issues, google server errors, etc. LogUtils.e("AppEngineDashboardAuthenticator", "Exception caught from GetAuthTokenCallback", e); mPostAuthenticateCallback.run(false); } } }, null); }
From source file:com.mobiperf.AccountSelector.java
/** * Return the list of account names for users to select *//*from w w w . j av a2 s. c o m*/ public static String[] getAccountList(Context context) { AccountManager accountManager = AccountManager.get(context.getApplicationContext()); Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE); int numAccounts = accounts == null ? 1 : accounts.length + 1; String[] accountNames = new String[numAccounts]; for (int i = 0; i < accounts.length; i++) { accountNames[i] = accounts[i].name; } accountNames[numAccounts - 1] = context.getString(R.string.defaultUser); return accountNames; }
From source file:com.lvlstudios.android.gtmessage.AppEngineClient.java
private HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken) throws Exception { Log.d(TAG, "AppEngineClient.makeRequestNoRetry: " + urlPath); // Get auth token for account - needs to be Google account so can piggy back on Google services. Account account = new Account(mAccountName, "com.google"); String authToken = getAuthToken(mContext, account); if (newToken) { // invalidate the cached token AccountManager accountManager = AccountManager.get(mContext); accountManager.invalidateAuthToken(account.type, authToken); authToken = getAuthToken(mContext, account); }// ww w . java 2 s . c om // Get ACSID cookie DefaultHttpClient client = new DefaultHttpClient(); String continueURL = BASE_URL; URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken); HttpGet method = new HttpGet(uri); final HttpParams getParams = new BasicHttpParams(); HttpClientParams.setRedirecting(getParams, false); // continue is not used method.setParams(getParams); HttpResponse res = client.execute(method); Header[] headers = res.getHeaders("Set-Cookie"); if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) { Log.w(TAG, "AppEngineClient " + urlPath + " authentication failed: " + res.getStatusLine().getStatusCode()); return res; } String ascidCookie = null; for (Header header : headers) { if (header.getValue().indexOf("ACSID=") >= 0) { // let's parse it String value = header.getValue(); String[] pairs = value.split(";"); ascidCookie = pairs[0]; } } // Make POST request uri = new URI(BASE_URL + urlPath); HttpPost post = new HttpPost(uri); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); post.setEntity(entity); post.setHeader("Cookie", ascidCookie); post.setHeader("X-Same-Domain", "1"); // XSRF res = client.execute(post); if (res.getStatusLine().getStatusCode() != 200) { Log.e(TAG, "AppEngineClient " + urlPath + " POST status: " + res.getStatusLine().getStatusCode()); } return res; }
From source file:com.meiste.greg.ptw.GAE.java
public static boolean isAccountSetupNeeded(final Context context) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final String account = prefs.getString(EditPreferences.KEY_ACCOUNT_EMAIL, ""); if (account.length() == 0) { // Account not setup at all return true; }/*from w w w . j ava2 s .c o m*/ final AccountManager mgr = AccountManager.get(context); final Account[] accts = mgr.getAccountsByType(ACCOUNT_TYPE); for (final Account acct : accts) { if (acct.name.equals(account)) { // Account setup and found on system return false; } } // Account setup, but no longer present on system final SharedPreferences.Editor editor = prefs.edit(); editor.putString(EditPreferences.KEY_ACCOUNT_EMAIL, null); editor.putString(EditPreferences.KEY_ACCOUNT_COOKIE, null); editor.apply(); return true; }
From source file:com.mobiperf_library.AccountSelector.java
/** * Return the list of account names for users to select *///from w ww. j a va2s . c om public static String[] getAccountList(Context context) { AccountManager accountManager = AccountManager.get(context.getApplicationContext()); Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE); int numAccounts = accounts == null ? 1 : accounts.length + 1; String[] accountNames = new String[numAccounts]; for (int i = 0; i < accounts.length; i++) { accountNames[i] = accounts[i].name; } accountNames[numAccounts - 1] = Config.DEFAULT_USER; return accountNames; }
From source file:be.evias.cloudLogin.cloudLoginMainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); checkConnection();//from ww w. j a va 2 s . co m mAccountManager = AccountManager.get(this); mAccountName = getIntent().getStringExtra(AccountManager.KEY_ACCOUNT_NAME); mAccount = new Account(mAccountName, AccountBase.ACCOUNT_TYPE); mContext = getBaseContext(); mPrefs = mContext.getSharedPreferences("cloudlogin", Context.MODE_PRIVATE); mNavigationDrawerFragment = (FragmentNavigationDrawer) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); /* Set up the drawer. */ mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); }