Add account only on jelly bean and above

This commit is contained in:
Dominik Schürmann
2014-08-21 11:36:47 +02:00
parent 0c1e65bc8b
commit 3c46c3c2df
2 changed files with 15 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Environment;
import android.provider.ContactsContract;
@@ -111,14 +112,17 @@ public class KeychainApplication extends Application {
}
public static void setupAccountAsNeeded(Context context) {
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
if (accounts == null || accounts.length == 0) {
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
if (manager.addAccountExplicitly(account, null, null)) {
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
} else {
Log.e(Constants.TAG, "Adding account failed!");
// only enabled for Jelly Bean because we need some newer methods in our sync adapter
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
if (accounts == null || accounts.length == 0) {
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
if (manager.addAccountExplicitly(account, null, null)) {
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
} else {
Log.e(Constants.TAG, "Adding account failed!");
}
}
}
}