List of usage examples for android.content Context ACCOUNT_SERVICE
String ACCOUNT_SERVICE
To view the source code for android.content Context ACCOUNT_SERVICE.
Click Source Link
From source file:org.linphone.ContactsManager.java
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 {//from w w w . j a va 2 s . co m accountManager.addAccountExplicitly(newAccount, null, null); mAccount = newAccount; } catch (Exception e) { Log.e(e); mAccount = null; } } else { mAccount = accounts[0]; } initializeContactManager(context, contentResolver); }
From source file:com.glandorf1.joe.wsprnetviewer.app.sync.WsprNetViewerSyncAdapter.java
/** * Create a new dummy account for the sync adapter * * @param context The application context *///from w w w.j av a 2 s .com 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 // app_name = WsprNetViewer // sync_account_type = wsprnetviewer.joe.glandorf1.com 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. boolean ret = accountManager.addAccountExplicitly(newAccount, "", null); if (!ret) { return null; } // If you don't set android:syncable="true" in // in your <provider> element in the manifest, // then call context.setIsSyncable(account, AUTHORITY, 1) // here. onAccountCreated(newAccount, context); } return newAccount; }