contacts work on all supported api levels

This commit is contained in:
Adithya Abraham Philip 2015-03-17 19:07:28 +05:30
parent dbcb7a9e10
commit 17181cbc19

View File

@ -118,24 +118,21 @@ public class KeychainApplication extends Application {
* @param context * @param context
*/ */
public static void setupAccountAsNeeded(Context context) { public static void setupAccountAsNeeded(Context context) {
// only enabled for Jelly Bean because we need some newer methods in our sync adapter try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { AccountManager manager = AccountManager.get(context);
try { Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
AccountManager manager = AccountManager.get(context); if (accounts == null || accounts.length == 0) {
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE); Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
if (accounts == null || accounts.length == 0) { if (manager.addAccountExplicitly(account, null, null)) {
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE); ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
if (manager.addAccountExplicitly(account, null, null)) { ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1); } else {
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); Log.e(Constants.TAG, "Adding account failed!");
} else {
Log.e(Constants.TAG, "Adding account failed!");
}
} }
} catch (SecurityException e) {
Log.e(Constants.TAG, "SecurityException when adding the account", e);
Toast.makeText(context, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show();
} }
} catch (SecurityException e) {
Log.e(Constants.TAG, "SecurityException when adding the account", e);
Toast.makeText(context, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show();
} }
} }