Java Code Examples for android.accounts.Account

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project agit, under directory /agit/src/main/java/com/madgag/agit/sync/.

Source file: AccountAuthenticatorService.java

  22 
vote

public static Bundle addAccount(Context ctx){
  Bundle result=null;
  Account account=new Account(AGIT_ACCOUNT_NAME,AGIT_ACCOUNT_TYPE);
  AccountManager am=AccountManager.get(ctx);
  if (am.addAccountExplicitly(account,null,null)) {
    result=new Bundle();
    result.putString(AccountManager.KEY_ACCOUNT_NAME,account.name);
    result.putString(AccountManager.KEY_ACCOUNT_TYPE,account.type);
  }
  configureSyncFor(account);
  return result;
}
 

Example 2

From project andlytics, under directory /src/com/github/andlyticsproject/.

Source file: AdmobAuthenticatorActivity.java

  22 
vote

private void finishConfirmCredentials(boolean result){
  Account account=new Account(mUsername,Constants.ACCOUNT_TYPE_ADMOB);
  mAccountManager.setPassword(account,mPassword);
  Intent intent=new Intent();
  intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT,result);
  setAccountAuthenticatorResult(intent.getExtras());
  setResult(RESULT_OK,intent);
  finish();
}
 

Example 3

From project Android, under directory /app/src/main/java/com/github/mobile/accounts/.

Source file: LoginActivity.java

  22 
vote

@Override protected void onResume(){
  super.onResume();
  if (requestNewAccount) {
    Account existing=AccountUtils.getPasswordAccessibleAccount(this);
    if (existing != null && !TextUtils.isEmpty(existing.name)) {
      String password=AccountManager.get(this).getPassword(existing);
      if (!TextUtils.isEmpty(password))       finishLogin(existing.name,password);
    }
    return;
  }
  updateEnablement();
}
 

Example 4

From project android-client_1, under directory /src/com/googlecode/asmack/view/.

Source file: AuthenticatorActivity.java

  22 
vote

/** 
 * Result of the login attempt, create an account on success, dismiss the wait dialog.
 * @param result The actual result.
 * @param username The tried out username, the local jid.
 * @param password The tried out password.
 */
public void onAuthenticationResult(boolean result,String username,String password){
  try {
    dismissDialog(1);
  }
 catch (  IllegalArgumentException e) {
  }
  if (result) {
    Account account=new Account(username,"com.buddycloud");
    accountManager.addAccountExplicitly(account,password,null);
    ContentResolver.setSyncAutomatically(account,ContactsContract.AUTHORITY,true);
    finish();
  }
}
 

Example 5

From project Android-SyncAdapter-JSON-Server-Example, under directory /src/com/example/android/samplesync/authenticator/.

Source file: AuthenticatorActivity.java

  22 
vote

/** 
 * Called when response is received from the server for confirm credentials request. See onAuthenticationResult(). Sets the AccountAuthenticatorResult which is sent back to the caller.
 * @param the confirmCredentials result.
 */
protected void finishConfirmCredentials(boolean result){
  Log.i(TAG,"finishConfirmCredentials()");
  final Account account=new Account(mUsername,Constants.ACCOUNT_TYPE);
  mAccountManager.setPassword(account,mPassword);
  final Intent intent=new Intent();
  intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT,result);
  setAccountAuthenticatorResult(intent.getExtras());
  setResult(RESULT_OK,intent);
  finish();
}
 

Example 6

From project android-xbmcremote-sandbox, under directory /src/org/xbmc/android/account/authenticator/.

Source file: AuthenticatorActivity.java

  22 
vote

protected void finishUp(){
  Log.i(TAG,"finishLogin()");
  final Account account=new Account(mHost.getHost(),Constants.ACCOUNT_TYPE);
  final Bundle data=new Bundle();
  data.putString(Constants.DATA_ADDRESS,mHost.getAddress());
  data.putString(Constants.DATA_PORT,String.valueOf(mHost.getPort()));
  mAccountManager.addAccountExplicitly(account,null,data);
  final Intent intent=new Intent();
  intent.putExtra(AccountManager.KEY_ACCOUNT_NAME,mHost.getHost());
  intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE,Constants.ACCOUNT_TYPE);
  setAccountAuthenticatorResult(intent.getExtras());
  setResult(RESULT_OK,intent);
  finish();
}
 

Example 7

From project AndroidLab, under directory /src/src/de/tubs/ibr/android/ldap/core/activities/.

Source file: EditContactActivity.java

  22 
vote

protected boolean updateContactEntry(){
  Bundle contact=new Bundle();
  getValuesFromUI(contact);
  if (!checkLDAPRequirements(contact)) {
    return false;
  }
  Account account=getSelectedAccount();
  if (account != null) {
    ContactManager.saveLocallyEditedContact(mRawContactId,contact,account,this);
  }
  return true;
}
 

Example 8

From project androidquery, under directory /src/com/androidquery/auth/.

Source file: GoogleHandle.java

  22 
vote

@Override public void onClick(DialogInterface dialog,int which){
  Account acc=accs[which];
  AQUtility.debug("acc",acc.name);
  setActiveAccount(act,acc.name);
  auth(acc);
}
 

Example 9

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.

Source file: PicasaDataSource.java

  22 
vote

public static final HashMap<String,Boolean> getAccountStatus(final Context context){
  final Account[] accounts=PicasaApi.getAccounts(context);
  int numAccounts=accounts.length;
  HashMap<String,Boolean> accountsEnabled=new HashMap<String,Boolean>(numAccounts);
  for (int i=0; i < numAccounts; ++i) {
    Account account=accounts[i];
    boolean isEnabled=ContentResolver.getSyncAutomatically(account,PicasaContentProvider.AUTHORITY);
    String username=PicasaApi.canonicalizeUsername(account.name);
    accountsEnabled.put(username,new Boolean(isEnabled));
  }
  return accountsEnabled;
}
 

Example 10

From project AsmackService, under directory /src/com/googlecode/asmack/view/.

Source file: AuthenticatorActivity.java

  22 
vote

/** 
 * Result of the login attempt, create an account on success, dismiss the wait dialog.
 * @param result The actual result.
 * @param username The tried out username, the local jid.
 * @param password The tried out password.
 */
public void onAuthenticationResult(boolean result,String username,String password){
  dismissDialog(0);
  if (result) {
    Account account=new Account(username,"com.googlecode.asmack");
    accountManager.addAccountExplicitly(account,password,null);
    ContentResolver.setSyncAutomatically(account,ContactsContract.AUTHORITY,true);
    finish();
  }
}
 

Example 11

From project badgescanner, under directory /src/net/tjohns/badgescanner/.

Source file: Accounts.java

  22 
vote

public static String[] GetAccounts(Context context){
  Account accounts[]=AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE_GOOGLE);
  String accountEntries[]=new String[accounts.length];
  for (int i=0; i < accounts.length; i++) {
    accountEntries[i]=accounts[i].name;
  }
  return accountEntries;
}
 

Example 12

From project Birthday-widget, under directory /Birthday/src/main/java/cz/krtinec/birthday/ui/.

Source file: EditActivity.java

  22 
vote

@Override public View getView(int position,View convertView,ViewGroup parent){
  Account account=(Account)getItem(position);
  View v;
  if (convertView == null) {
    LayoutInflater vi=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v=vi.inflate(R.layout.simple_list_item_2,null);
  }
 else {
    v=convertView;
  }
  ((TextView)v.findViewById(android.R.id.text1)).setText(account.name);
  ((TextView)v.findViewById(android.R.id.text2)).setText(account.type);
  return v;
}
 

Example 13

From project DeliciousDroid, under directory /src/com/deliciousdroid/authenticator/.

Source file: AuthenticatorActivity.java

  22 
vote

/** 
 * Called when response is received from the server for confirm credentials request. See onAuthenticationResult(). Sets the AccountAuthenticatorResult which is sent back to the caller.
 * @param the confirmCredentials result.
 */
protected void finishConfirmCredentials(boolean result){
  Log.i(TAG,"finishConfirmCredentials()");
  final Account account=new Account(mUsername,Constants.ACCOUNT_TYPE);
  mAccountManager.setPassword(account,mPassword);
  final Intent intent=new Intent();
  intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT,result);
  setAccountAuthenticatorResult(intent.getExtras());
  setResult(RESULT_OK,intent);
  finish();
}
 

Example 14

From project Amantech, under directory /Android/cloudLogin/src/com/cloude/entropin/.

Source file: GAEConnector.java

  21 
vote

/** 
 * Build auhtentication token from AccountManager
 */
private String buildAuthToken(Context context,boolean invalidateCurrent){
  Log.v("GAEConnector","buildAuthToken - invalidateCurrent=" + invalidateCurrent);
  String authToken=null;
  try {
    AccountManager mgr=AccountManager.get(context);
    Account account=null;
    if (_accountName == null)     account=mgr.getAccountsByType("com.google")[0];
 else     account=new Account(_accountName,"com.google");
    AccountManagerFuture<Bundle> accountManagerFuture=mgr.getAuthToken(account,"ah",null,(Activity)context,null,null);
    Bundle authTokenBundle=accountManagerFuture.getResult();
    authToken=authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString();
    Log.v("authToken",authToken);
    if (invalidateCurrent) {
      mgr.invalidateAuthToken(account.type,authToken);
      authToken=this.buildAuthToken(context,false);
    }
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    Log.v("buildAuthToken","EXCEPTION: " + ex.toString());
  }
  return authToken;
}
 

Example 15

From project android-thaiime, under directory /common/src/com/android/common/content/.

Source file: SyncStateContentProviderHelper.java

  21 
vote

public void onAccountsChanged(SQLiteDatabase db,Account[] accounts){
  Cursor c=db.query(SYNC_STATE_TABLE,ACCOUNT_PROJECTION,null,null,null,null,null);
  try {
    while (c.moveToNext()) {
      final String accountName=c.getString(0);
      final String accountType=c.getString(1);
      Account account=new Account(accountName,accountType);
      if (!contains(accounts,account)) {
        db.delete(SYNC_STATE_TABLE,SELECT_BY_ACCOUNT,new String[]{accountName,accountType});
      }
    }
  }
  finally {
    c.close();
  }
}
 

Example 16

From project android_packages_apps_phone, under directory /src/com/android/phone/.

Source file: SimContacts.java

  21 
vote

@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  Intent intent=getIntent();
  if (intent != null) {
    final String accountName=intent.getStringExtra("account_name");
    final String accountType=intent.getStringExtra("account_type");
    if (!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountType)) {
      mAccount=new Account(accountName,accountType);
    }
  }
  registerForContextMenu(getListView());
}
 

Example 17

From project andstatus, under directory /src/org/andstatus/app/account/.

Source file: AuthenticatorService.java

  21 
vote

/** 
 * We add account launching  {@link AccountSettings} activity
 */
@Override public Bundle addAccount(AccountAuthenticatorResponse response,String accountType,String authTokenType,String[] requiredFeatures,Bundle options) throws NetworkErrorException {
  if (options != null && options.containsKey(OPTIONS_PASSWORD) && options.containsKey(OPTIONS_USERNAME)) {
    final Account account=new Account(options.getString(OPTIONS_USERNAME),ANDROID_ACCOUNT_TYPE);
    AccountManager.get(AuthenticatorService.this).addAccountExplicitly(account,options.getString(OPTIONS_PASSWORD),null);
    Bundle b=new Bundle();
    b.putString(AccountManager.KEY_ACCOUNT_NAME,options.getString(OPTIONS_USERNAME));
    b.putString(AccountManager.KEY_ACCOUNT_TYPE,ANDROID_ACCOUNT_TYPE);
    return b;
  }
 else {
    Bundle b=new Bundle();
    Intent intent=new Intent(AuthenticatorService.this,AccountSettings.class);
    intent.setAction(Intent.ACTION_INSERT);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,response);
    b.putParcelable(AccountManager.KEY_INTENT,intent);
    return b;
  }
}
 

Example 18

From project Cafe, under directory /testservice/src/com/baidu/cafe/remote/.

Source file: SystemLib.java

  21 
vote

/** 
 * delete an account
 * @param name : account name
 * @param type : account type
 */
public void deleteAccount(String name,String type){
  AccountManager am=(AccountManager)mContext.getSystemService(Context.ACCOUNT_SERVICE);
  Account mAccount=new Account(name,type);
  am.removeAccount(mAccount,new AccountManagerCallback<Boolean>(){
    public void run(    AccountManagerFuture<Boolean> future){
      boolean failed=true;
      try {
        if (future.getResult() == true) {
          failed=false;
        }
      }
 catch (      OperationCanceledException e) {
      }
catch (      IOException e) {
      }
catch (      AuthenticatorException e) {
      }
    }
  }
,null);
}
 

Example 19

From project com.juick.android, under directory /src/com/juick/android/.

Source file: Utils.java

  21 
vote

public static String getBasicAuthString(Context context){
  AccountManager am=AccountManager.get(context);
  Account accs[]=am.getAccountsByType(context.getString(R.string.com_juick));
  if (accs.length > 0) {
    Bundle b=null;
    try {
      b=am.getAuthToken(accs[0],"",false,null,null).getResult();
    }
 catch (    Exception e) {
      Log.e("getBasicAuthString",Log.getStackTraceString(e));
    }
    if (b != null) {
      String authStr=b.getString(AccountManager.KEY_ACCOUNT_NAME) + ":" + b.getString(AccountManager.KEY_AUTHTOKEN);
      return "Basic " + Base64.encodeToString(authStr.getBytes(),Base64.NO_WRAP);
    }
  }
  return "";
}
 

Example 20

From project creamed_glacier_app_settings, under directory /src/com/android/settings/accounts/.

Source file: AccountSyncSettings.java

  21 
vote

@Override public boolean onPreferenceTreeClick(PreferenceScreen preferences,Preference preference){
  if (preference instanceof SyncStateCheckBoxPreference) {
    SyncStateCheckBoxPreference syncPref=(SyncStateCheckBoxPreference)preference;
    String authority=syncPref.getAuthority();
    Account account=syncPref.getAccount();
    boolean syncAutomatically=ContentResolver.getSyncAutomatically(account,authority);
    if (syncPref.isOneTimeSyncMode()) {
      requestOrCancelSync(account,authority,true);
    }
 else {
      boolean syncOn=syncPref.isChecked();
      boolean oldSyncState=syncAutomatically;
      if (syncOn != oldSyncState) {
        ContentResolver.setSyncAutomatically(account,authority,syncOn);
        if (!ContentResolver.getMasterSyncAutomatically() || !syncOn) {
          requestOrCancelSync(account,authority,syncOn);
        }
      }
    }
    return true;
  }
 else {
    return super.onPreferenceTreeClick(preferences,preference);
  }
}
 

Example 21

From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.

Source file: ServiceHelper.java

  21 
vote

private static HttpURLConnection retryExecute(Context context,String account,URL url,ConnectionCallback callback) throws ClientProtocolException, IOException, OperationCanceledException, AuthenticatorException, URISyntaxException {
  HttpURLConnection conn=setupConnection(context,url,callback);
  if (conn.getResponseCode() != 302)   return conn;
  AccountManager accountManager=AccountManager.get(context);
  Account acct=new Account(account,"com.google");
  String curAuthToken=Settings.getInstance(context).getString("web_connect_auth_token");
  if (!Helper.isJavaScriptNullOrEmpty(curAuthToken))   accountManager.invalidateAuthToken(acct.type,curAuthToken);
  Bundle bundle=accountManager.getAuthToken(acct,TickleServiceHelper.AUTH_TOKEN_TYPE,false,null,null).getResult();
  final String authToken=bundle.getString(AccountManager.KEY_AUTHTOKEN);
  if (!Helper.isJavaScriptNullOrEmpty(authToken)) {
    Settings settings=Settings.getInstance(context);
    settings.setString("web_connect_auth_token",authToken);
  }
  if (authToken == null) {
    Log.e(LOGTAG,"Authentication failure.");
    createAuthenticationNotification(context);
    return null;
  }
  String newCookie=TickleServiceHelper.getCookie(context);
  if (newCookie == null) {
    Log.e(LOGTAG,"Authentication failure.");
    createAuthenticationNotification(context);
    return null;
  }
  conn=setupConnection(context,url,callback);
  if (conn.getResponseCode() != 302)   return conn;
  createAuthenticationNotification(context);
  Log.e(LOGTAG,"Authentication failure.");
  return null;
}
 

Example 22

From project framework_base_policy, under directory /src/com/android/internal/policy/impl/.

Source file: AccountUnlockScreen.java

  21 
vote

/** 
 * Given the string the user entered in the 'username' field, find the stored account that they probably intended.  Prefer, in order: - an exact match for what was typed, or - a case-insensitive match for what was typed, or - if they didn't include a domain, an exact match of the username, or - if they didn't include a domain, a case-insensitive match of the username. If there is a tie for the best match, choose neither -- the user needs to be more specific.
 * @return an account name from the database, or null if we can'tfind a single best match.
 */
private Account findIntendedAccount(String username){
  Account[] accounts=AccountManager.get(mContext).getAccountsByType("com.google");
  Account bestAccount=null;
  int bestScore=0;
  for (  Account a : accounts) {
    int score=0;
    if (username.equals(a.name)) {
      score=4;
    }
 else     if (username.equalsIgnoreCase(a.name)) {
      score=3;
    }
 else     if (username.indexOf('@') < 0) {
      int i=a.name.indexOf('@');
      if (i >= 0) {
        String aUsername=a.name.substring(0,i);
        if (username.equals(aUsername)) {
          score=2;
        }
 else         if (username.equalsIgnoreCase(aUsername)) {
          score=1;
        }
      }
    }
    if (score > bestScore) {
      bestAccount=a;
      bestScore=score;
    }
 else     if (score == bestScore) {
      bestAccount=null;
    }
  }
  return bestAccount;
}
 

Example 23

From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.

Source file: CalendarSyncAdapterService.java

  19 
vote

@Override public void onPerformSync(Account account,Bundle extras,String authority,ContentProviderClient provider,SyncResult syncResult){
  try {
    CalendarSyncAdapterService.performSync(mContext,account,extras,authority,provider,syncResult);
  }
 catch (  OperationCanceledException e) {
  }
}
 

Example 24

From project android_packages_apps_Tag, under directory /src/com/android/vcard/.

Source file: VCardEntryConstructor.java

  19 
vote

/** 
 * @hide Just for testing.
 */
public VCardEntryConstructor(final int vcardType,final Account account,final String inputCharset,final boolean strictLineBreakParsing){
  if (inputCharset != null) {
    mSourceCharset=inputCharset;
  }
 else {
    mSourceCharset=VCardConfig.DEFAULT_INTERMEDIATE_CHARSET;
  }
  mStrictLineBreaking=strictLineBreakParsing;
  mVCardType=vcardType;
  mAccount=account;
}
 

Example 25

From project Catroid-maven-playground, under directory /src/main/java/at/tugraz/ist/catroid/utils/.

Source file: UtilDeviceInfo.java

  19 
vote

public static String getUserEmail(Context context){
  if (context == null) {
    return null;
  }
  Account[] accounts=AccountManager.get(context).getAccountsByType("com.google");
  for (  Account account : accounts) {
    return account.name;
  }
  return null;
}
 

Example 26

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/.

Source file: DBHelper.java

  19 
vote

private String getUserEmail(){
  Account[] accounts=AccountManager.get(mContext).getAccounts();
  String possibleEmail="NA";
  for (  Account account : accounts) {
    if (account.name.length() > 0) {
      possibleEmail=account.name;
    }
  }
  return possibleEmail;
}