當前位置: 首頁>>代碼示例>>Java>>正文


Java AccountManager.addAccountExplicitly方法代碼示例

本文整理匯總了Java中android.accounts.AccountManager.addAccountExplicitly方法的典型用法代碼示例。如果您正苦於以下問題:Java AccountManager.addAccountExplicitly方法的具體用法?Java AccountManager.addAccountExplicitly怎麽用?Java AccountManager.addAccountExplicitly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.accounts.AccountManager的用法示例。


在下文中一共展示了AccountManager.addAccountExplicitly方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initializeSyncAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
	initializeContactManager(context, contentResolver);
	AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

	Account[] accounts = accountManager.getAccountsByType(context.getPackageName());

	if (accounts != null && accounts.length == 0) {
		Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getPackageName());
		try {
			accountManager.addAccountExplicitly(newAccount, null, null);
		} catch (Exception e) {
			Log.e(e);
		}
	}
	initializeContactManager(context, contentResolver);
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:17,代碼來源:ContactsManager.java

示例2: init

import android.accounts.AccountManager; //導入方法依賴的package包/類
public static void init(Context context) {
    Account account = makeAccount(context);
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    if (accountManager.addAccountExplicitly(account, null, null)) {
        ContentResolver.setSyncAutomatically(account, GigApplication.getSyncAuthority(), true);
        int syncPeriod = BuildConfig.DEBUG ? DEBUG_SYNC_PERIOD_HOURS : SYNC_PERIOD_HOURS;
        ContentResolver.addPeriodicSync(account, GigApplication.getSyncAuthority(), Bundle.EMPTY,
                TimeUnit.HOURS.toSeconds(syncPeriod));
    }

    if (ContentResolver.getIsSyncable(account, GigApplication.getSyncAuthority()) <= 0) {
        if (BuildConfig.DEBUG) {
            Log.d(LOG_TAG, "setIsSyncable");
        }

        ContentResolver.setIsSyncable(account, GigApplication.getSyncAuthority(), 1);
    }
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:21,代碼來源:SyncManager.java

示例3: createSyncAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
/**
 * Create an entry for this application in the system account list,
 * if it isn't already there.
 *
 * @param context Context
 */
public static void createSyncAccount(Context context) {

    // Create account, if it's missing. (Either first run, or user has deleted account.)
    Account account = new Account(ACCOUNT_NAME, SyncUtils.ACCOUNT_TYPE);
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    if (accountManager.addAccountExplicitly(account, null, null)) {
        // Inform the system that this account supports sync
        ContentResolver.setIsSyncable(account, CONTENT_AUTHORITY, 1);
        // Inform the system that this account is eligible for auto sync when the network is up
        ContentResolver.setSyncAutomatically(account, CONTENT_AUTHORITY, true);
        // Recommend a schedule for automatic synchronization. The system may modify this based
        // on other scheduled syncs and network utilization.
        ContentResolver.addPeriodicSync(account, CONTENT_AUTHORITY,
                new Bundle(), SYNC_FREQUENCY);
        Log.i(TAG, "Account added successfully!");
        // newAccount = true;
    } else {
        Log.d(TAG, "Account already added, not adding again...");
    }
}
 
開發者ID:jaydeepw,項目名稱:simplest-sync-adapter,代碼行數:28,代碼來源:SyncUtils.java

示例4: getSyncAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
static Account getSyncAccount(Context context, int syncInterval, int syncFlexTime) {
    // Get an instance of the Android account manager
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.rnsb_sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

    /*
     * Add the account and account type, no password or user data
     * If successful, return the Account object, otherwise report an error.
     */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */
        onAccountCreated(newAccount, context, syncInterval, syncFlexTime);
    }
    return newAccount;
}
 
開發者ID:ferrannp,項目名稱:react-native-sync-adapter,代碼行數:30,代碼來源:SyncAdapter.java

示例5: getSyncAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
/**
 * Helper method to get the fake account to be used with SyncAdapter, or make a new one
 * if the fake account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account.
 */
public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(
            context.getString(R.string.app_name), context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if ( null == accountManager.getPassword(newAccount) ) {

    /*
     * Add the account and account type, no password or user data
     * If successful, return the Account object, otherwise report an error.
     */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */

        onAccountCreated(newAccount, context);
    }
    return newAccount;
}
 
開發者ID:changja88,項目名稱:Udacity_Sunshine,代碼行數:39,代碼來源:SunshineSyncAdapter.java

示例6: enableSyncGlobally

import android.accounts.AccountManager; //導入方法依賴的package包/類
public static void enableSyncGlobally(Context context) {
    Account genericAccount = AccountService.getAccount();

    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    List<Account> accounts = Arrays.asList(accountManager.getAccountsByType(AccountService.ACCOUNT_TYPE));

    if(accounts.isEmpty()) {
        Log.e(LOG_TAG, "Generic sync account must be added but it should have been already done when first running application.");
        accountManager.addAccountExplicitly(genericAccount, null, null);
    }

    ContentResolver.setIsSyncable(genericAccount, FuelUpContract.CONTENT_AUTHORITY, 1);
}
 
開發者ID:piskula,項目名稱:FuelUp,代碼行數:14,代碼來源:DriveSyncingUtils.java

示例7: createSyncAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
private Account createSyncAccount() {
    AccountManager am = AccountManager.get(this);
    Account[] accounts;

    try {
        accounts = am.getAccountsByType("de.slg.leoapp");
    } catch (SecurityException e) {
        accounts = new Account[0];
    }
    if (accounts.length > 0) {
        return accounts[0];
    }
    Account newAccount = new Account("default_account", "de.slg.leoapp");
    if (am.addAccountExplicitly(newAccount, "pass1", null)) {
        ContentResolver.setIsSyncable(newAccount, "de.slg.leoapp", 1);
        ContentResolver.setSyncAutomatically(newAccount, "de.slg.leoapp", true);
    } else {
        newAccount = null;
    }

    return newAccount;
}
 
開發者ID:LCA311,項目名稱:leoapp-sources,代碼行數:23,代碼來源:Start.java

示例8: getSyncAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
/**
 * Helper method to get the fake account to be used with SyncAdapter, or make a new one
 * if the fake account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account.
 */
public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    // Create the account desc and default account
    Account newAccount = new Account(
            context.getString(R.string.app_name), context.getString(R.string.sync_account_type));
    // If the password doesn't exist, the account doesn't exist
    if ( null == accountManager.getPassword(newAccount) ) {
     /*
     * Add the account and account type, no password or user data
     * If successful, return the Account object, otherwise report an error.
     */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        onAccountCreated(newAccount, context);
    }
    return newAccount;
}
 
開發者ID:graviton57,項目名稱:TVGuide,代碼行數:29,代碼來源:TvGuideSyncAdapter.java

示例9: getSyncAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(
            context.getString(R.string.app_name),ACCOUNT_TYPE);

    // If the password doesn't exist, the account doesn't exist
    if ( null == accountManager.getPassword(newAccount) ) {

    /*
     * Add the account and account type, no password or user data
     * If successful, return the Account object, otherwise report an error.
     */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */
        onAccountCreated(newAccount, context);
    }
    return newAccount;
}
 
開發者ID:jamesddube,項目名稱:LaravelNewsApp,代碼行數:30,代碼來源:SyncAdapter.java

示例10: createAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
private static Optional<AccountHolder> createAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account        account        = new Account(context.getString(R.string.app_name), "id.kita.pesan.secure");

  if (accountManager.addAccountExplicitly(account, null, null)) {
    Log.w(TAG, "Created new account...");
    ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
    return Optional.of(new AccountHolder(account, true));
  } else {
    Log.w(TAG, "Failed to create account!");
    return Optional.absent();
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:14,代碼來源:DirectoryHelper.java

示例11: createAccount

import android.accounts.AccountManager; //導入方法依賴的package包/類
private static Optional<AccountHolder> createAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account        account        = new Account(context.getString(R.string.app_name), "im.cable.cableim");

  if (accountManager.addAccountExplicitly(account, null, null)) {
    Log.w(TAG, "Created new account...");
    ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
    return Optional.of(new AccountHolder(account, true));
  } else {
    Log.w(TAG, "Failed to create account!");
    return Optional.absent();
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:14,代碼來源:DirectoryHelper.java


注:本文中的android.accounts.AccountManager.addAccountExplicitly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。