当前位置: 首页>>代码示例>>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;未经允许,请勿转载。