List of usage examples for android.accounts AccountManager KEY_ACCOUNT_NAME
String KEY_ACCOUNT_NAME
To view the source code for android.accounts AccountManager KEY_ACCOUNT_NAME.
Click Source Link
From source file:saschpe.birthdays.helper.AccountHelper.java
public static Bundle addAccount(Context context) { Log.d(TAG, "AccountHelper.addAccount: Adding account..."); final Account account = new Account(context.getString(R.string.app_name), context.getString(R.string.account_type)); AccountManager manager = AccountManager.get(context); if (manager.addAccountExplicitly(account, null, null)) { // Enable automatic sync once per day ContentResolver.setSyncAutomatically(account, context.getString(R.string.content_authority), true); ContentResolver.setIsSyncable(account, context.getString(R.string.content_authority), 1); // Add periodic sync interval based on user preference final long freq = PreferencesHelper.getPeriodicSyncFrequency(context); ContentResolver.addPeriodicSync(account, context.getString(R.string.content_authority), new Bundle(), freq);//from www. ja v a2 s. c o m Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); Log.i(TAG, "Account added: " + account.name); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { manager.notifyAccountAuthenticated(account); } return result; } else { Log.e(TAG, "Adding account explicitly failed!"); return null; } }
From source file:org.geometerplus.android.fbreader.network.BearerAuthenticator.java
static boolean onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { final BearerAuthenticator ba = ourAuthenticators.get(activity); boolean processed = true; try {// www . j a v a2s . c om switch (requestCode) { default: processed = false; break; case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER: if (resultCode == Activity.RESULT_OK && data != null) { ba.myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); } break; case NetworkLibraryActivity.REQUEST_AUTHORISATION: if (resultCode == Activity.RESULT_OK) { ba.myAuthorizationConfirmed = true; } break; case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN: if (resultCode == Activity.RESULT_OK && data != null) { final CookieStore store = ZLNetworkManager.Instance().cookieStore(); final Map<String, String> cookies = (Map<String, String>) data .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY); if (cookies != null) { for (Map.Entry<String, String> entry : cookies.entrySet()) { final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue()); c.setDomain(data.getData().getHost()); c.setPath("/"); final Calendar expire = Calendar.getInstance(); expire.add(Calendar.YEAR, 1); c.setExpiryDate(expire.getTime()); c.setSecure(true); c.setDiscard(false); store.addCookie(c); } } } break; } } finally { if (processed) { synchronized (ba) { ba.notifyAll(); } } return processed; } }
From source file:saschpe.birthdays.helper.AccountHelper.java
/** * Adds account and forces manual sync afterwards if adding was successful */// ww w . j ava2 s .c om public static Bundle addAccountAndSync(Context context, Handler backgroundStatusHandler) { final Bundle result = addAccount(context); if (result != null) { if (result.containsKey(AccountManager.KEY_ACCOUNT_NAME)) { BirthdaysIntentService.startActionSync(context, backgroundStatusHandler); return result; } else { Log.e(TAG, "Unable to add account. Result did not contain KEY_ACCOUNT_NAME"); } } else { Log.e(TAG, "Unable to add account. Result was null."); } return null; }
From source file:dev.drsoran.moloko.auth.AuthenticatorActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.authenticator_activity); setSupportProgressBarIndeterminateVisibility(false); accountManager = AccountManager.get(this); createStartFragment();// www. j a v a 2 s. c o m isNewAccount = getIntent().getStringExtra(AccountManager.KEY_ACCOUNT_NAME) == null; }
From source file:com.textuality.gpstats.GPlusSnowflake.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == GPS_REQUEST_CODE && resultCode == RESULT_OK) { mAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); get("https://www.googleapis.com/plus/v1/people/me", mAccount, "oauth2:https://www.googleapis.com/auth/plus.me", null, new ResponseHandler() { @Override// w ww .jav a2s .c o m public void handle(Response response) { if (response.status != 200) { barf(response); return; } try { JSONObject json = new JSONObject(new String(response.body)); mID = json.optString("id"); readFeedPage(null); } catch (JSONException je) { throw new RuntimeException(je); } } }); } }
From source file:org.geometerplus.android.fbreader.network.ActivityNetworkContext.java
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { boolean processed = true; try {/* w w w.j av a2 s .c om*/ switch (requestCode) { default: processed = false; break; case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER: if (resultCode == Activity.RESULT_OK && data != null) { myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); } break; case NetworkLibraryActivity.REQUEST_AUTHORISATION: if (resultCode == Activity.RESULT_OK) { myAuthorizationConfirmed = true; } break; case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN: if (resultCode == Activity.RESULT_OK && data != null) { final CookieStore store = cookieStore(); final Map<String, String> cookies = (Map<String, String>) data .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY); if (cookies != null) { for (Map.Entry<String, String> entry : cookies.entrySet()) { final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue()); c.setDomain(data.getData().getHost()); c.setPath("/"); final Calendar expire = Calendar.getInstance(); expire.add(Calendar.YEAR, 1); c.setExpiryDate(expire.getTime()); c.setSecure(true); c.setDiscard(false); store.addCookie(c); } } } break; } } finally { if (processed) { synchronized (this) { notifyAll(); } } return processed; } }
From source file:org.birthdayadapter.util.AccountHelper.java
/** * Add account for Birthday Adapter to Android system *///from www . j a v a 2 s . c o m public Bundle addAccountAndSync() { Log.d(Constants.TAG, "Adding account..."); // enable automatic sync once per day ContentResolver.setSyncAutomatically(Constants.ACCOUNT, Constants.CONTENT_AUTHORITY, true); ContentResolver.setIsSyncable(Constants.ACCOUNT, Constants.ACCOUNT_TYPE, 1); // add periodic sync interval once per day long freq = AlarmManager.INTERVAL_DAY; ContentResolver.addPeriodicSync(Constants.ACCOUNT, Constants.ACCOUNT_TYPE, new Bundle(), freq); AccountManager am = AccountManager.get(mContext); if (am.addAccountExplicitly(Constants.ACCOUNT, null, null)) { Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, Constants.ACCOUNT.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT.type); // Force a sync! Even when background sync is disabled, this will force one sync! manualSync(); return result; } else { return null; } }
From source file:com.kinvey.sample.signin.GoogleLoginActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == GPLAY_REQUEST_CODE && resultCode == RESULT_OK) { mAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); get(PLUS_PEOPLE_ME, mAccount, SCOPE_STRING, null, new ResponseHandler() { @Override//from w w w.jav a2 s . c o m public void handle(Response response) { if (response.status != 200) { error(response); return; } try { JSONObject json = new JSONObject(new String(response.body)); mID = json.optString("id"); loginGoogleKinveyUser(); } catch (JSONException je) { throw new RuntimeException(je); } } }); } }
From source file:it.gmariotti.android.examples.googleaccount.GPickerActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (requestCode == PICK_ACCOUNT_REQUEST && resultCode == RESULT_OK) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); Toast.makeText(this, "Account Name=" + accountName, 3000).show(); }/*from ww w . ja v a2s . c o m*/ }
From source file:com.pindroid.activity.SaveReadLaterBookmark.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode != Constants.REQUEST_CODE_ACCOUNT_CHANGE) { Log.e(TAG, "Unsupported request code: " + requestCode); finish();//from w w w .j a va 2 s . com } else { if (resultCode == Activity.RESULT_CANCELED) { finish(); } else if (resultCode == Activity.RESULT_OK) { app.setUsername(data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME)); handleIntent(); } } }