List of usage examples for android.accounts AccountManager getAccountsByType
@NonNull
public Account[] getAccountsByType(String type)
From source file:net.translatewiki.app.TranslateWikiApp.java
/** @return api instance for this application */ @Override/*from ww w . j a v a 2 s. c o m*/ public Account getCurrentAccount() { if (currentAccount == null) { AccountManager accountManager = AccountManager.get(this); Account[] allAccounts = accountManager.getAccountsByType(getString(R.string.account_type_identifier)); if (allAccounts.length != 0) { currentAccount = allAccounts[0]; } } return currentAccount; }
From source file:com.ntsync.android.sync.activities.MainActivity.java
private void updateButtonState() { AccountManager accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE); boolean accountAvailable = accounts != null && accounts.length > 0; this.findViewById(R.id.btnImport).setEnabled(accountAvailable); this.findViewById(R.id.btnAccount).setEnabled(accountAvailable); }
From source file:com.ntsync.android.sync.activities.ViewKeyPasswordActivity.java
private void refreshAccountList() { FragmentManager mgr = getSupportFragmentManager(); AccountManager accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE); FragmentTransaction trans = mgr.beginTransaction(); boolean isFirst = true; for (Account currAccount : accounts) { AccountFragment fragment = new AccountFragment(); Bundle args = new Bundle(); args.putString(AccountFragment.PARAM_ACCOUNT_NAME, currAccount.name); fragment.setArguments(args);/*w ww. j a v a2 s . com*/ if (isFirst) { trans.replace(R.id.accountContainer, fragment); isFirst = false; } else { trans.add(R.id.accountContainer, fragment); } } trans.commit(); }
From source file:com.juick.android.Utils.java
public static boolean hasAuth(Context context) { AccountManager am = AccountManager.get(context); Account accs[] = am.getAccountsByType(context.getString(R.string.com_juick)); return accs.length > 0; }
From source file:org.tigase.mobile.roster.AccountSelectorDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(context); AccountManager accountManager = AccountManager.get(context); ArrayList<String> accList = new ArrayList<String>(); for (Account account : accountManager.getAccountsByType(Constants.ACCOUNT_TYPE)) { accList.add(account.name);/*from w ww . ja v a 2s .c o m*/ } final String[] items = accList.toArray(new String[] {}); builder.setTitle("Select account"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { dismiss(); Intent intent = new Intent(getActivity(), ContactEditActivity.class); intent.putExtra("account", items[item]); startActivityForResult(intent, 0); } }); return builder.create(); }
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 www. j av a 2 s .c om*/ 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.Duo.music.player.Dialogs.GooglePlayMusicAuthenticationDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { parentActivity = getActivity();//from w w w. j a v a 2s.c om AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); sharedPreferences = parentActivity.getSharedPreferences("com.jams.music.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.jelly.music.player.Dialogs.GooglePlayMusicAuthenticationDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { parentActivity = getActivity();//from w w w .ja v a 2 s . c o m AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); sharedPreferences = parentActivity.getSharedPreferences("com.jelly.music.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.aniruddhc.acemusic.player.Dialogs.GooglePlayMusicAuthenticationDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { parentActivity = getActivity();//www . ja va2s . c om 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.noswap.keyring.MainActivity.java
public void doGCMStuff() { GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { Log.v(TAG, "Registering"); GCMRegistrar.register(this, SENDER_ID); } else {// ww w .java2 s . c o m Log.v(TAG, "Already registered: " + regId); } AccountManager am = AccountManager.get(this); Account[] accounts = am.getAccountsByType("com.google"); for (Account account : accounts) { Log.v(TAG, "Account: " + account.name + " (" + account.type + ")"); } if (accounts.length > 0) { Account account = accounts[0]; Bundle options = new Bundle(); am.getAuthToken(account, "Keyring", options, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> result) { try { Bundle bundle = result.getResult(); String token = bundle.getString(AccountManager.KEY_AUTHTOKEN); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { startActivityForResult(intent, 0); return; } Log.v(TAG, "onTokenAcquired: " + token); } catch (Exception e) { Log.v(TAG, "onTokenAcquired exception: " + e.toString()); } } }, new Handler() { }); } }