Example usage for android.accounts AccountManager removeAccount

List of usage examples for android.accounts AccountManager removeAccount

Introduction

In this page you can find the example usage for android.accounts AccountManager removeAccount.

Prototype

@Deprecated
public AccountManagerFuture<Boolean> removeAccount(final Account account,
        AccountManagerCallback<Boolean> callback, Handler handler) 

Source Link

Document

Removes an account from the AccountManager.

Usage

From source file:Main.java

/**
 * Remove specified account/*from   ww w  .  ja va2s  .  c  o m*/
 * @param context context
 * @param account account to remove
 */
public static void removeAccount(Context context, Account account) {
    final AccountManager accountManager = AccountManager.get(context);
    accountManager.removeAccount(account, null, null);
}

From source file:Main.java

/**
 * Recreate account/*from  w  ww  .  ja v a  2  s .com*/
 * @param account account
 * @param authTokenType authTokenType
 * @param requiredFeatures requiredFeatures, could be <code>null</code>
 * @param options options, could be <code>null</code>
 * @param activity activity (cannot be <code>null</code>)
 */
public static void reCreateAccount(Account account, String accountType, String authTokenType,
        String[] requiredFeatures, Bundle options, Activity activity) {
    if (activity == null) {
        throw new IllegalArgumentException("activity cannot be null");
    }

    final AccountManager accountManager = AccountManager.get(activity.getApplicationContext());
    if (isAccountExist(activity, account)) {
        accountManager.removeAccount(account, null, null);
    }

    accountManager.addAccount(accountType, authTokenType, requiredFeatures, options, activity, null, null);
}

From source file:saschpe.birthdays.helper.AccountHelper.java

/**
 * Remove account from Android system/* w w  w.ja  v  a  2s  .  c  o m*/
 */
public static boolean removeAccount(Context context) {
    Log.d(TAG, "Removing account...");
    AccountManager manager = AccountManager.get(context);
    final Account account = new Account(context.getString(R.string.app_name),
            context.getString(R.string.account_type));
    AccountManagerFuture<Boolean> future = manager.removeAccount(account, null, null);
    if (future.isDone()) {
        try {
            future.getResult();
            return true;
        } catch (Exception e) {
            Log.e(TAG, "Problem while removing account!", e);
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.birthdayadapter.util.AccountHelper.java

/**
 * Remove account from Android system// w  ww. j  ava 2  s. c  o m
 */
public boolean removeAccount() {
    Log.d(Constants.TAG, "Removing account...");

    AccountManager am = AccountManager.get(mContext);

    // remove account
    AccountManagerFuture<Boolean> future = am.removeAccount(Constants.ACCOUNT, null, null);
    if (future.isDone()) {
        try {
            future.getResult();

            return true;
        } catch (Exception e) {
            Log.e(Constants.TAG, "Problem while removing account!", e);
            return false;
        }
    } else {
        return false;
    }
}

From source file:eu.trentorise.smartcampus.launcher.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {//from ww  w  . j  av  a 2  s.co m
        initGlobalConstants();
        AccountManager am = AccountManager.get(this);
        Account[] accounts = am.getAccountsByType("eu.trentorise.smartcampus.account");
        if (accounts != null && accounts.length > 0) {
            am.removeAccount(accounts[0], null, null);
        }
        SCAccessProvider.getInstance(this).logout(this);
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(this, getString(R.string.auth_failed), Toast.LENGTH_SHORT).show();
        finish();
    }

    // Getting saved instance
    if (savedInstanceState == null) {
        // Loading first fragment that works as home for application.
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        Fragment frag = new AppFragment();
        ft.add(R.id.fragment_container, frag).commit();
    }
}

From source file:com.owncloud.android.ui.activity.FirstRunActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first_run_activity);

    boolean isProviderOrOwnInstallationVisible = getResources()
            .getBoolean(R.bool.show_provider_or_own_installation);

    setSlideshowSize(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);

    Button loginButton = findViewById(R.id.login);
    loginButton.setBackgroundColor(Color.WHITE);
    loginButton.setTextColor(Color.BLACK);

    loginButton.setOnClickListener(v -> {
        if (getIntent().getBooleanExtra(EXTRA_ALLOW_CLOSE, false)) {
            Intent authenticatorActivityIntent = new Intent(this, AuthenticatorActivity.class);
            authenticatorActivityIntent.putExtra(AuthenticatorActivity.EXTRA_USE_PROVIDER_AS_WEBLOGIN, false);
            startActivityForResult(authenticatorActivityIntent, FIRST_RUN_RESULT_CODE);
        } else {//from ww  w .  java2 s . c om
            finish();
        }
    });

    Button providerButton = findViewById(R.id.signup);
    providerButton.setBackgroundColor(getResources().getColor(R.color.primary_dark));
    providerButton.setTextColor(getResources().getColor(R.color.login_text_color));
    providerButton.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
    providerButton.setOnClickListener(v -> {
        Intent authenticatorActivityIntent = new Intent(this, AuthenticatorActivity.class);
        authenticatorActivityIntent.putExtra(AuthenticatorActivity.EXTRA_USE_PROVIDER_AS_WEBLOGIN, true);

        if (getIntent().getBooleanExtra(EXTRA_ALLOW_CLOSE, false)) {
            startActivityForResult(authenticatorActivityIntent, FIRST_RUN_RESULT_CODE);
        } else {
            authenticatorActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(authenticatorActivityIntent);
        }
    });

    TextView hostOwnServerTextView = findViewById(R.id.host_own_server);
    hostOwnServerTextView.setTextColor(getResources().getColor(R.color.login_text_color));
    hostOwnServerTextView.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);

    progressIndicator = findViewById(R.id.progressIndicator);
    ViewPager viewPager = findViewById(R.id.contentPanel);

    // Sometimes, accounts are not deleted when you uninstall the application so we'll do it now
    if (isFirstRun(this)) {
        AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
        if (am != null) {
            for (Account account : AccountUtils.getAccounts(this)) {
                am.removeAccount(account, null, null);
            }
        }
    }

    FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(),
            getFirstRun());
    progressIndicator.setNumberOfSteps(featuresViewAdapter.getCount());
    viewPager.setAdapter(featuresViewAdapter);

    viewPager.addOnPageChangeListener(this);
}

From source file:com.lambdasoup.watchlater.test.AddActivityTest.java

@Before
public void setUp() throws Exception {

    // inject retrofit http executor for espresso idling resource
    Field httpExecutor = AddActivity.class.getDeclaredField("OPTIONAL_RETROFIT_HTTP_EXECUTOR");
    httpExecutor.setAccessible(true);//from ww  w  . j av a  2 s  . c o m
    idlingExecutor = new RetrofitHttpExecutorIdlingResource();
    httpExecutor.set(AddActivity.class, idlingExecutor);
    registerIdlingResources(idlingExecutor);

    // inject test account type
    Field accountType = AddActivity.class.getDeclaredField("ACCOUNT_TYPE_GOOGLE");
    accountType.setAccessible(true);
    accountType.set(AddActivity.class, TEST_ACCOUNT_TYPE);

    // clear accounts
    AccountManager accountManager = AccountManager
            .get(InstrumentationRegistry.getInstrumentation().getContext());
    //noinspection ResourceType,deprecation
    accountManager.removeAccount(ACCOUNT_1, null, null).getResult();
    //noinspection ResourceType,deprecation
    accountManager.removeAccount(ACCOUNT_2, null, null).getResult();

    // inject mock backend
    Field endpoint = AddActivity.class.getDeclaredField("YOUTUBE_ENDPOINT");
    endpoint.setAccessible(true);
    endpoint.set(AddActivity.class, mockWebServer.url("/").toString());
}

From source file:com.github.pockethub.android.ui.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    int itemId = menuItem.getItemId();

    if (itemId == R.id.navigation_home) {
        switchFragment(new HomePagerFragment(), org);
        getSupportActionBar().setTitle(getString(R.string.app_name));
        return true;
    } else if (itemId == R.id.navigation_gists) {
        switchFragment(new GistsPagerFragment(), null);
        getSupportActionBar().setTitle(menuItem.getTitle());
        return true;
    } else if (itemId == R.id.navigation_issue_dashboard) {
        switchFragment(new IssueDashboardPagerFragment(), null);
        getSupportActionBar().setTitle(menuItem.getTitle());
        return true;
    } else if (itemId == R.id.navigation_bookmarks) {
        switchFragment(new FilterListFragment(), null);
        getSupportActionBar().setTitle(menuItem.getTitle());
        return true;
    } else if (itemId == R.id.navigation_log_out) {
        AccountManager accountManager = getAccountManager();
        Account[] allGitHubAccounts = accountManager.getAccountsByType(getString(R.string.account_type));

        for (Account account : allGitHubAccounts) {
            accountManager.removeAccount(account, null, null);
        }//  w w  w  .j  a  v  a2  s  .c  o m

        Intent in = new Intent(this, LoginActivity.class);
        in.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(in);
        finish();
        return false;

    } else if (menuItemOrganizationMap.containsKey(menuItem)) {
        switchFragment(new HomePagerFragment(), menuItemOrganizationMap.get(menuItem));
        navigationView.getMenu().findItem(R.id.navigation_home).setChecked(true);
        return false;
    } else {
        throw new IllegalStateException("MenuItem " + menuItem + " not known");
    }
}

From source file:org.hfoss.posit.android.sync.Communicator.java

/**
 * Removes an account. This should be called when, e.g., the user changes
 * to a new server./*from   ww w. j  av  a2s.com*/
 * @param context
 * @param accountType
 */
public static void removeAccount(Context context, String accountType) {
    AccountManager am = AccountManager.get(context);
    am.invalidateAuthToken(accountType, SyncAdapter.AUTHTOKEN_TYPE);
    Account[] accounts = am.getAccountsByType(accountType);
    if (accounts.length != 0)
        am.removeAccount(accounts[0], null, null);
    //String authkey = getAuthKey(context);
    //return authkey == null;
}

From source file:com.sintef_energy.ubisolar.activities.DrawerActivity.java

/**
 * Logout From the app/*from  ww  w.  j  a v  a2 s .  c o  m*/
 */
private void performLogout(Context context) {
    Session session = Session.getActiveSession();
    if (session != null) {
        if (!session.isClosed()) {
            session.closeAndClearTokenInformation();
            //clear your preferences if saved
        }
    } else {
        session = new Session(context);
        Session.setActiveSession(session);

        session.closeAndClearTokenInformation();
        //clear your preferences if saved
    }

    /* UPDATE VIEW */
    changeNavdrawerSessionsView(false);
    Utils.makeLongToast(getApplicationContext(), getResources().getString(R.string.fb_logout));

    /* REMOVE ACCOUNT */
    AccountManager accountManager = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);

    Account[] accounts = accountManager.getAccounts();
    for (Account account : accounts) {
        if (account.type.intern().equals(ACCOUNT_TYPE)) {
            Log.v(TAG, "Removing account: " + account.name + " for authority: " + AUTHORITY_PROVIDER);
            accountManager.removeAccount(account, null, new Handler());
        }
    }

    /* REMOVE PREFERENCES*/
    PreferencesManager.getInstance().clearSessionData();

    /* REMOVE DATA*/
    getContentResolver().delete(
            EnergyContract.Devices.CONTENT_URI.buildUpon().appendPath(EnergyContract.DELETE).build(), null,
            null);
    getContentResolver().delete(
            EnergyContract.Energy.CONTENT_URI.buildUpon().appendPath(EnergyContract.DELETE).build(), null,
            null);
}