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.example.android.samplesync.syncadapter.SyncAdapter.java

public SyncAdapter(Context context, boolean autoInitialize) {
    super(context, autoInitialize);
    mContext = context;//from  w  w  w .j  a  va  2s .c o m
    mAccountManager = AccountManager.get(context);
    Log.e(TAG, "SyncAdapter==============oncrate");
}

From source file:com.aniruddhc.acemusic.player.Dialogs.GooglePlayMusicAuthenticationDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    parentActivity = getActivity();//from  w ww.  j  a va  2s.  c  o  m
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    sharedPreferences = parentActivity.getSharedPreferences("com.aniruddhc.acemusic.player",
            Context.MODE_PRIVATE);
    View rootView = parentActivity.getLayoutInflater().inflate(R.layout.dialog_google_authentication_layout,
            null);

    //Check if this dialog was called from the Welcome sequence.
    mFirstRun = getArguments().getBoolean(Common.FIRST_RUN);

    infoText = (TextView) rootView.findViewById(R.id.google_authentication_dialog_text);
    infoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
    infoText.setPaintFlags(infoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    final Account[] accounts = accountManager.getAccountsByType("com.google");
    final int size = accounts.length;
    String[] accountNames = new String[size];

    for (int i = 0; i < size; i++) {
        accountNames[i] = accounts[i].name;
    }

    //Set the dialog title.
    builder.setTitle(R.string.sign_in_google_play_music);
    builder.setCancelable(false);
    builder.setItems(accountNames, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            account = accounts[which];
            sharedPreferences.edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name).commit();
            AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(
                    parentActivity.getApplicationContext(), parentActivity, mFirstRun, account.name);

            task.execute();

        }

    });

    return builder.create();
}

From source file:com.newtifry.android.ChooseAccount.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AccountManager accountManager = AccountManager.get(getApplicationContext());

    // Sync our database. Only on create.
    NewtifryAccount.FACTORY.syncAccountList(this, accountManager);

    // Set the layout, and allow text filtering.
    setContentView(R.layout.screen_accounts);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    getListView().setTextFilterEnabled(true);
}

From source file:com.nextgis.maplib.map.LayerFactory.java

public Connection getConnectionFromAccount(Context context, String accountName) {
    final AccountManager accountManager = AccountManager.get(context);
    for (Account account : accountManager.getAccountsByType(NGW_ACCOUNT_TYPE)) {
        if (account.name.equals(accountName)) {
            String url = accountManager.getUserData(account, "url");
            String password = accountManager.getPassword(account);
            String login = accountManager.getUserData(account, "login");
            return new Connection(accountName, login, password, url);
        }//from  w  w w  .j av  a  2  s  .c  om
    }
    return null;
}

From source file:com.zoterodroid.activity.BrowseCitations.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse_bookmarks);

    mAccountManager = AccountManager.get(this);
    mAccount = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE)[0];
    mContext = this;

    Log.d("browse bookmarks", getIntent().getDataString());
    Uri data = getIntent().getData();//  w  w w .j ava 2  s .  co  m
    String scheme = data.getScheme();
    String path = data.getPath();
    Log.d("path", path);
    String username = data.getQueryParameter("username");
    String tagname = data.getQueryParameter("tagname");
    String recent = data.getQueryParameter("recent");

    myself = mAccount.name.equals(username);

    ArrayList<Citation> citationList = new ArrayList<Citation>();

    if (scheme.equals("content") && path.equals("/citations") && myself) {

        try {

            String[] projection = new String[] { Citation._ID, Citation.Title, Citation.Key,
                    Citation.Creator_Summary, Citation.Item_Type };
            String selection = null;
            String sortorder = null;

            selection = Citation.Account + " = '" + username + "'";

            Uri citations = Citation.CONTENT_URI;

            Cursor c = managedQuery(citations, projection, selection, null, sortorder);

            if (c.moveToFirst()) {
                int idColumn = c.getColumnIndex(Citation._ID);
                int titleColumn = c.getColumnIndex(Citation.Title);
                int keyColumn = c.getColumnIndex(Citation.Key);
                int creatorSummaryColumn = c.getColumnIndex(Citation.Creator_Summary);
                int itemTypeColumn = c.getColumnIndex(Citation.Item_Type);

                do {

                    Citation b = new Citation(c.getInt(idColumn), c.getString(titleColumn),
                            c.getString(keyColumn), c.getString(creatorSummaryColumn),
                            c.getString(itemTypeColumn));

                    citationList.add(b);

                } while (c.moveToNext());

            }

            setListAdapter(new CitationListAdapter(this, R.layout.bookmark_view, citationList));
        } catch (Exception e) {
        }

    }

    lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        }
    });

    /* Add Context-Menu listener to the ListView. */
    lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            menu.setHeaderTitle("Actions");
            if (myself) {
                menu.add(Menu.NONE, 0, Menu.NONE, "Delete");
            } else {
                menu.add(Menu.NONE, 1, Menu.NONE, "Add");
            }

        }
    });
}

From source file:com.ntsync.android.sync.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SystemHelper.initSystem(this);

    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        GingerbreadHelper.setStrictMode();
    }//from w w  w.  j  av a2  s  .c  o  m

    setContentView(R.layout.activity_main);

    PaymentVerificationService.startVerificationTimer(getApplicationContext());

    // Check if account available (but not for resume)
    if (savedInstanceState == null) {
        AccountManager accountManager = AccountManager.get(this);
        Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
        if (accounts == null || accounts.length == 0) {
            // Show Login / Register Activity
            Intent intent = new Intent(this, AuthenticatorActivity.class);
            startActivity(intent);
        }
    }
    initViewPeopleBtn();
}

From source file:com.digitalarx.android.syncadapter.AbstractOwnCloudSyncAdapter.java

public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) {
    super(context, autoInitialize, allowParallelSyncs);
    this.setAccountManager(AccountManager.get(context));
}

From source file:com.deliciousdroid.syncadapter.ContactSyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {/*w  w  w.  j a  va2s. com*/
    List<User> users;
    List<Status> statuses;
    try {

        final AccountManager am = AccountManager.get(mContext);

        authtoken = am.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE, false);

        // fetch updates from the sample service over the cloud
        users = DeliciousFeed.fetchFriendUpdates(account);
        // update platform contacts.
        Log.d(TAG, "Calling contactManager's sync contacts");
        ContactManager.syncContacts(mContext, account.name, users);
        // fetch and update status messages for all the synced users.

        if (Build.VERSION.SDK_INT >= 15) {
            ContactManager.insertStreamStatuses(mContext, account.name);
        } else {
            statuses = DeliciousFeed.fetchFriendStatuses(account);
            ContactManager.insertStatuses(mContext, account.name, statuses);
        }
    } catch (final IOException e) {
        Log.e(TAG, "IOException", e);
        syncResult.stats.numIoExceptions++;
    } catch (final AuthenticationException e) {
        mAccountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, authtoken);
        syncResult.stats.numAuthExceptions++;
        Log.e(TAG, "AuthenticationException", e);
    } catch (final ParseException e) {
        syncResult.stats.numParseExceptions++;
        Log.e(TAG, "ParseException", e);
    } catch (final JSONException e) {
        syncResult.stats.numParseExceptions++;
        Log.e(TAG, "JSONException", e);
    } catch (final FeedForbiddenException e) {
        Log.e(TAG, "FeedForbiddenException");
    } catch (final AuthenticatorException e) {
        Log.e(TAG, "AuthenticatorException");
    } catch (final OperationCanceledException e) {
        Log.e(TAG, "OperationCanceledException");
    }
}

From source file:com.pindroid.syncadapter.BookmarkSyncAdapter.java

public BookmarkSyncAdapter(Context context, boolean autoInitialize) {
    super(context, autoInitialize);
    mContext = context;
    mAccountManager = AccountManager.get(context);
}