List of usage examples for android.accounts Account Account
public Account(@NonNull Account other, @NonNull String accessId)
From source file:com.hybris.mobile.lib.commerce.provider.CatalogProvider.java
@Override public boolean onCreate() { authority = getContext().getString(R.string.sync_default_authority); String dbName = getContext().getString(R.string.sync_default_db_name); int dbVersion = getContext().getResources().getInteger(R.integer.sync_default_db_version); try {//from w ww . ja v a 2 s .c om ComponentName componentName = new ComponentName(getContext(), this.getClass()); // Authority name from the manifest file String tmpAuthority = getContext().getPackageManager().getProviderInfo(componentName, PackageManager.GET_META_DATA).authority; if (StringUtils.isNotBlank(tmpAuthority)) { authority = tmpAuthority; } // Database configuration from manifest file Bundle bundle = getContext().getPackageManager().getProviderInfo(componentName, PackageManager.GET_META_DATA).metaData; if (bundle != null) { String dbNameTmp = bundle.getString(getContext().getString(R.string.sync_db_name)); int dbVersionTmp = bundle.getInt(getContext().getString(R.string.sync_db_version)); if (StringUtils.isNotBlank(dbNameTmp)) { dbName = dbNameTmp; } if (dbVersion != 0) { dbVersion = dbVersionTmp; } } // Account name and type componentName = new ComponentName(getContext(), CatalogAuthenticatorService.class); bundle = getContext().getPackageManager().getServiceInfo(componentName, PackageManager.GET_META_DATA).metaData; String accountName = bundle.getString(getContext().getString(R.string.sync_account_name)); String accountType = bundle.getString(getContext().getString(R.string.sync_account_type)); if (StringUtils.isBlank(accountName) || StringUtils.isBlank(accountType)) { throw new IllegalArgumentException( "You must provide the metadata " + getContext().getString(R.string.sync_account_name) + ", " + getContext().getString(R.string.sync_account_type) + " for " + this.getClass()); } account = new Account(accountType, accountName); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Package name not found. Details:" + e.getLocalizedMessage()); throw new IllegalArgumentException( "Error getting the information from the metadata of " + this.getClass()); } // Unit test case - the mock context does not have any package manager or provider info catch (UnsupportedOperationException e) { Log.e(TAG, "Unsupported operation:" + e.getLocalizedMessage()); } mDatabaseHelper = new CatalogDatabaseHelper(getContext(), dbName, dbVersion); URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); URI_MATCHER.addURI(authority, CatalogContract.Provider.SEGMENT_GROUP, CatalogContract.Provider.CODE_GROUP); URI_MATCHER.addURI(authority, CatalogContract.Provider.SEGMENT_GROUP + "/*", CatalogContract.Provider.CODE_GROUP_ID); URI_MATCHER.addURI(authority, CatalogContract.Provider.SEGMENT_DATA, CatalogContract.Provider.CODE_DATA); URI_MATCHER.addURI(authority, CatalogContract.Provider.SEGMENT_DATA + "/*", CatalogContract.Provider.CODE_DATA_ID); URI_MATCHER.addURI(authority, CatalogContract.Provider.SEGMENT_DATA_DETAILS, CatalogContract.Provider.CODE_DATA_DETAILS); URI_MATCHER.addURI(authority, CatalogContract.Provider.SEGMENT_DATA_DETAILS + "/*", CatalogContract.Provider.CODE_DATA_DETAILS_ID); URI_MATCHER.addURI(authority, CatalogContract.Provider.SEGMENT_SYNC_GROUP + "/*", CatalogContract.Provider.CODE_SYNC_GROUP); return true; }
From source file:de.msal.shoutemo.connector.GetPostsService.java
@Override public void onCreate() { super.onCreate(); broadcaster = LocalBroadcastManager.getInstance(this); mAccountManager = AccountManager.get(this); Account[] acc = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); /* No account; push the user into adding one */ if (acc.length == 0) { Log.v(TAG, "No suitable account found, directing user to add one."); mAccountManager.addAccount(AccountAuthenticator.ACCOUNT_TYPE, null, null, new Bundle(), null, new AccountManagerCallback<Bundle>() { @Override/*from w w w .j a va 2 s. c om*/ public void run(AccountManagerFuture<Bundle> result) { Bundle bundle; try { bundle = result.getResult(); } catch (OperationCanceledException e) { e.printStackTrace(); return; } catch (AuthenticatorException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } /* no accounts saved, yet; ask the user for credentials */ Intent launch = bundle.getParcelable(AccountManager.KEY_INTENT); if (launch != null) { launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(launch); return; } mAccount = new Account(bundle.getString(AccountManager.KEY_ACCOUNT_NAME), bundle.getString(AccountManager.KEY_ACCOUNT_TYPE)); Log.v(TAG, "Added account " + mAccount.name + "; now fetching new posts."); startGetPostsTask(); } }, null); } else { mAccount = acc[0]; startGetPostsTask(); } }
From source file:com.nextgis.maplibui.NGWLoginFragment.java
@Override public void onLoadFinished(Loader<String> loader, String token) { if (loader.getId() == R.id.auth_token_loader) { if (token != null && token.length() > 0) { String name = ""; try { String url = mURL.getText().toString(); if (!url.startsWith("http")) url = "http://" + url; URI uri = new URI(url); if (uri.getHost() != null && uri.getHost().length() > 0) name += uri.getHost(); if (uri.getPort() != 80 && uri.getPort() > 0) name += ":" + uri.getPort(); if (uri.getPath() != null && uri.getPath().length() > 0) name += uri.getPath(); } catch (URISyntaxException e) { name = mURL.getText().toString(); }//from w ww .j a v a 2s.c om ((NGWLoginActivity) getActivity()).onTokenReceived(new Account(name, NGW_ACCOUNT_TYPE), mLogin.getText().toString(), mPassword.getText().toString(), mURL.getText().toString(), token); } else { Toast.makeText(getActivity(), R.string.error_login, Toast.LENGTH_SHORT).show(); } } }
From source file:be.evias.cloudLogin.cloudLoginRunPointActivity.java
/** * Add new account to the account manager for the cloudLogin * account type./*from w w w . j a v a2 s. c o m*/ * * @param accountType String * @param authTokenType String */ private void addNewAccount(String accountType, String authTokenType) { final AccountManagerFuture<Bundle> future = mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); showMessage(getBaseContext().getString(R.string.message_account_created), Toast.LENGTH_SHORT); Log.d("cloudLogin", "AddNewAccount Bundle is " + bnd); final Account account = new Account(bnd.getString(AccountManager.KEY_ACCOUNT_NAME), bnd.getString(AccountManager.KEY_ACCOUNT_TYPE)); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", true); editor.putString("cloudlogin_active_account_name", account.name); editor.commit(); displayNavigationDrawer(bnd, account); } catch (Exception e) { e.printStackTrace(); showMessage(e.getMessage(), Toast.LENGTH_LONG); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", false); editor.commit(); } } }, null); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.AccountActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_letterboxed_when_large); final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_FINISH_INTENT)) { mFinishIntent = intent.getParcelableExtra(EXTRA_FINISH_INTENT); }/*w w w . j a v a2 s. co m*/ if (savedInstanceState == null) { if (!AccountUtils.isAuthenticated(this)) { getSupportFragmentManager().beginTransaction() .add(R.id.root_container, new SignInMainFragment(), "signin_main").commit(); } else { mChosenAccount = new Account(AccountUtils.getChosenAccountName(this), "com.google"); getSupportFragmentManager().beginTransaction().add(R.id.root_container, SignInSetupFragment.makeFragment(SETUP_ATTENDEE), "setup_attendee").commit(); } } else { String accountName = savedInstanceState.getString(KEY_CHOSEN_ACCOUNT); if (accountName != null) { mChosenAccount = new Account(accountName, "com.google"); // mPlusClient = (new PlusClient.Builder(this, this, this)) // .setAccountName(accountName) // .setScopes(AccountUtils.AUTH_SCOPES) // .build(); } } }
From source file:com.prestomation.android.androidfiledrop.AppEngineClient.java
public String getASCIDCookie(boolean https) throws Exception { // Get auth token for account Account account = new Account(mAccountName, "com.google"); String authToken = getAuthToken(mContext, account); if (authToken == null) { throw new PendingAuthException(mAccountName); }//from w w w . j a va 2s . c o m AccountManager accountManager = AccountManager.get(mContext); accountManager.invalidateAuthToken(account.type, authToken); authToken = getAuthToken(mContext, account); // Get ACSID cookie DefaultHttpClient client = new DefaultHttpClient(); String continueURL = BASE_URL; String sURI = AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken; if (https == false) { sURI = sURI.replace("https", "http"); } URI uri = new URI(sURI); 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) { return res.toString(); } 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]; } } Log.i("AndroidFileDrop", "Received ASCIDCookie: " + ascidCookie); return ascidCookie; }
From source file:com.google.android.apps.iosched.ui.AccountActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_letterboxed_when_large); final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_FINISH_INTENT)) { mFinishIntent = intent.getParcelableExtra(EXTRA_FINISH_INTENT); }/*from w w w . j a v a 2s .co m*/ if (savedInstanceState == null) { if (!AccountUtils.isAuthenticated(this)) { getSupportFragmentManager().beginTransaction() .add(R.id.root_container, new SignInMainFragment(), "signin_main").commit(); } else { mChosenAccount = new Account(AccountUtils.getChosenAccountName(this), "com.google"); getSupportFragmentManager().beginTransaction().add(R.id.root_container, SignInSetupFragment.makeFragment(SETUP_ATTENDEE), "setup_attendee").commit(); } } else { String accountName = savedInstanceState.getString(KEY_CHOSEN_ACCOUNT); if (accountName != null) { mChosenAccount = new Account(accountName, "com.google"); mPlusClient = (new PlusClient.Builder(this, this, this)).setAccountName(accountName) .setScopes(AccountUtils.AUTH_SCOPES).build(); } } }
From source file:io.github.hidroh.materialistic.data.SyncDelegate.java
@UiThread public static void scheduleSync(Context context, Job job) { if (!Preferences.Offline.isEnabled(context)) { return;// ww w.java 2 s. c o m } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !TextUtils.isEmpty(job.id)) { JobInfo.Builder builder = new JobInfo.Builder(Long.valueOf(job.id).intValue(), new ComponentName(context.getPackageName(), ItemSyncJobService.class.getName())) .setRequiredNetworkType( Preferences.Offline.isWifiOnly(context) ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY) .setExtras(job.toPersistableBundle()); if (Preferences.Offline.currentConnectionEnabled(context)) { builder.setOverrideDeadline(0); } ((JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(builder.build()); } else { Bundle extras = new Bundle(job.toBundle()); extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); Account syncAccount; AccountManager accountManager = AccountManager.get(context); Account[] accounts = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID); if (accounts.length == 0) { syncAccount = new Account(SYNC_ACCOUNT_NAME, BuildConfig.APPLICATION_ID); accountManager.addAccountExplicitly(syncAccount, null, null); } else { syncAccount = accounts[0]; } ContentResolver.requestSync(syncAccount, MaterialisticProvider.PROVIDER_AUTHORITY, extras); } }
From source file:co.carlosjimenez.android.currencyalerts.app.sync.ForexSyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one * if the fake account doesn't exist yet. If we make a new account, we call the * onAccountCreated method so we can initialize things. * * @param context The context used to access the account service * @return a fake account./* w w w .j a v a 2 s. c o m*/ */ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { /* * Add the account and account type, no password or user data * If successful, return the Account object, otherwise report an error. */ if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } /* * If you don't set android:syncable="true" in * in your <provider> element in the manifest, * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1) * here. */ onAccountCreated(newAccount, context); } return newAccount; }
From source file:com.jackie.sunshine.app.sync.SunshineSyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one * if the fake account doesn't exist yet. If we make a new account, we call the * onAccountCreated method so we can initialize things. * * @param context The context used to access the account service * @return a fake account./*from w w w. j a v a 2s .c o m*/ */ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (manager.getPassword(newAccount) == null) { /* * Add the account and account type, no password or user data * If successful, return the Account object, otherwise report an error. */ if (!manager.addAccountExplicitly(newAccount, "", null)) return null; /* * If you don't set android:syncable="true" in * in your <provider> element in the manifest, * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1) * here. */ onAccountCreated(newAccount, context); } return newAccount; }