本文整理汇总了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);
}
示例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);
}
}
示例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...");
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}