Example usage for android.accounts AccountManager get

List of usage examples for android.accounts AccountManager get

Introduction

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

Prototype

public static AccountManager get(Context context) 

Source Link

Document

Gets an AccountManager instance associated with a Context.

Usage

From source file:com.deliciousdroid.activity.FragmentBaseActivity.java

@Override
@TargetApi(14)// w  w  w  .  j a v a 2s . co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mContext = this;
    mAccountManager = AccountManager.get(this);
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    loadSettings();
    init();

    if (android.os.Build.VERSION.SDK_INT >= 14) {
        getActionBar().setHomeButtonEnabled(true);
    }

    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction()) && !intent.hasExtra("MainSearchResults")) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(this, MainSearchResults.class);
            i.putExtras(intent.getExtras());
            startActivity(i);
            finish();
        } else {
            onSearchRequested();
        }
    } else if (Constants.ACTION_SEARCH_SUGGESTION.equals(intent.getAction())) {
        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);
            startActivity(i);
            finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())
                && intent.hasExtra(SearchManager.USER_QUERY)) {
            Intent viewBookmark = new Intent(this, ViewBookmark.class);
            viewBookmark.setAction(Intent.ACTION_VIEW);
            viewBookmark.setData(data);
            viewBookmark.removeExtra(SearchManager.USER_QUERY);
            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(this, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            finish();
        }
    }
}

From source file:com.aniruddhc.acemusic.player.WelcomeActivity.GooglePlayMusicFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;/*from  w  w w.j  a  v  a  2s.  co m*/
    View rootView = (View) inflater.inflate(R.layout.fragment_welcome_screen_5, null);

    welcomeHeader = (TextView) rootView.findViewById(R.id.welcome_header);
    welcomeHeader.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Light"));

    welcomeText1 = (TextView) rootView.findViewById(R.id.welcome_text_1);
    welcomeText1.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular"));

    googlePlayMusicDisclaimer = (TextView) rootView.findViewById(R.id.google_play_music_disclaimer);
    googlePlayMusicDisclaimer.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular"));

    radioGroup = (RadioGroup) rootView.findViewById(R.id.google_play_music_radio_group);

    final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    final Account[] accounts = accountManager.getAccountsByType("com.google");
    final int size = accounts.length + 1; //We're adding 1 here to account (no pun intended) for the extra "Don't use Google Play Music" option.

    final RadioButton[] radioButton = new RadioButton[size];

    //Add a new radio button the group for each username.
    for (int i = 0; i < size; i++) {
        radioButton[i] = new RadioButton(getActivity());
        radioGroup.addView(radioButton[i]);

        //The first radio button will always be "Don't use Google Play Music".
        if (i == 0) {
            radioButton[i].setChecked(true);
            radioButton[i].setText(R.string.dont_use_google_play_music);
        } else {
            radioButton[i].setText(accounts[i - 1].name);
        }

        radioButton[i].setTag(i);
        radioButton[i].setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));

    }

    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            int radioButtonID = group.getCheckedRadioButtonId();
            View radioButton = group.findViewById(radioButtonID);
            int index = group.indexOfChild(radioButton);

            if (index != 0) {

                account = accounts[index - 1];
                mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name)
                        .commit();

                AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext,
                        getActivity(), true, account.name);

                task.execute();
            } else {
                mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", "").commit();
                mApp.getSharedPreferences().edit().putBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false).commit();
            }

        }

    });

    return rootView;
}

From source file:org.klnusbaum.udj.PlayersLoader.java

public PlayersLoader(Context context, Account account, String query) {
    super(context);
    am = AccountManager.get(context);
    this.account = account;
    this.location = null;
    this.players = null;
    this.searchQuery = query;
    locationSearch = false;/*  ww  w  .j a  va  2s . c om*/
}

From source file:org.klnusbaum.udj.EventsLoader.java

public EventsLoader(Context context, Account account, String query) {
    super(context);
    am = AccountManager.get(context);
    this.account = account;
    this.location = null;
    this.events = null;
    this.searchQuery = query;
    locationSearch = false;//from   w  ww  . j ava2  s . com
}

From source file:com.friedran.appengine.dashboard.client.AppEngineDashboardAuthenticator.java

public void invalidateAuthToken() {
    if (mAuthToken == null) {
        LogUtils.e("AppEngineDashboardAuthenticator", "AuthToken hasn't been retrieved yet..");
        return;/*from  w  w w .j  a  v  a  2  s  . c  om*/
    }

    LogUtils.i("AppEngineDashboardAuthenticator", "Invalidating the previous authToken: " + mAuthToken);
    AccountManager.get(mApplicationContext).invalidateAuthToken(mAccount.type, mAuthToken);
    mAuthToken = null;
}

From source file:be.evias.cloudLogin.cloudLoginRunPointActivity.java

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

    mAccountManager = AccountManager.get(this);
    mContext = getBaseContext();/*www  .java  2s  .  co  m*/
    mPrefs = mContext.getSharedPreferences("cloudlogin", Context.MODE_PRIVATE);

    findViewById(R.id.create_select_account).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            displayAccountPicker(AUTHTOKEN_TYPE_FULL_ACCESS);
        }
    });

    displayAccountPicker(AUTHTOKEN_TYPE_FULL_ACCESS);

    if (savedInstanceState != null) {
        boolean showDialog = savedInstanceState.getBoolean(STATE_DIALOG);
        if (showDialog)
            displayAccountPicker(AUTHTOKEN_TYPE_FULL_ACCESS);
    }
}

From source file:com.ocp.picasa.PicasaApi.java

public static AuthAccount[] getAuthenticatedAccounts(Context context) {
    AccountManager accountManager = AccountManager.get(context);
    Account[] accounts = getAccounts(context);
    if (accounts == null)
        accounts = new Account[0];
    int numAccounts = accounts.length;

    ArrayList<AuthAccount> authAccounts = new ArrayList<AuthAccount>(numAccounts);
    for (int i = 0; i != numAccounts; ++i) {
        Account account = accounts[i];/*  ww  w .  jav  a 2  s. c  o  m*/
        String authToken;
        try {
            // Get the token without user interaction.
            authToken = accountManager.blockingGetAuthToken(account, PicasaService.SERVICE_NAME, true);

            // TODO: Remove this once the build is signed by Google, since
            // we will always have permission.
            // This code requests permission from the user explicitly.
            if (context instanceof Activity) {
                Bundle bundle = accountManager
                        .getAuthToken(account, PicasaService.SERVICE_NAME, null, (Activity) context, null, null)
                        .getResult();
                authToken = bundle.getString("authtoken");
                PicasaService.requestSync(context, PicasaService.TYPE_USERS_ALBUMS, -1);
            }

            // Add the account information to the list of accounts.
            if (authToken != null) {
                String username = canonicalizeUsername(account.name);
                authAccounts.add(new AuthAccount(username, authToken, account));
            }
        } catch (OperationCanceledException e) {
        } catch (IOException e) {
        } catch (AuthenticatorException e) {
        } catch (Exception e) {
            ;
        }
    }
    AuthAccount[] authArray = new AuthAccount[authAccounts.size()];
    authAccounts.toArray(authArray);
    return authArray;
}

From source file:at.bitfire.davdroid.syncadapter.AccountDetailsFragment.java

void addAccount() {
    ServerInfo serverInfo = (ServerInfo) getArguments().getSerializable(KEY_SERVER_INFO);
    String accountName = editAccountName.getText().toString();

    AccountManager accountManager = AccountManager.get(getActivity());
    Account account = new Account(accountName, Constants.ACCOUNT_TYPE);
    Bundle userData = new Bundle();
    userData.putString(Constants.ACCOUNT_KEY_BASE_URL, serverInfo.getBaseURL());
    userData.putString(Constants.ACCOUNT_KEY_USERNAME, serverInfo.getUserName());
    userData.putString(Constants.ACCOUNT_KEY_AUTH_PREEMPTIVE, Boolean.toString(serverInfo.isAuthPreemptive()));

    boolean syncContacts = false;
    for (ServerInfo.ResourceInfo addressBook : serverInfo.getAddressBooks())
        if (addressBook.isEnabled()) {
            userData.putString(Constants.ACCOUNT_KEY_ADDRESSBOOK_PATH, addressBook.getPath());
            ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
            syncContacts = true;//  w  w w.  ja v  a 2  s  .  co  m
            continue;
        }
    if (syncContacts) {
        ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
        ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
    } else
        ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 0);

    if (accountManager.addAccountExplicitly(account, serverInfo.getPassword(), userData)) {
        // account created, now create calendars
        ContentResolver.setIsSyncable(account, "com.android.calendar", 0);

        getActivity().finish();
    } else
        Toast.makeText(getActivity(), "Couldn't create account (account with this name already existing?)",
                Toast.LENGTH_LONG).show();
}

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);
        }//  w  w  w  .ja  v a  2s  .c  o m
    }
}