mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 16:38:50 -05:00
Add account only on jelly bean and above
This commit is contained in:
parent
0c1e65bc8b
commit
3c46c3c2df
@ -25,6 +25,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
|
||||||
@ -111,14 +112,17 @@ public class KeychainApplication extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setupAccountAsNeeded(Context context) {
|
public static void setupAccountAsNeeded(Context context) {
|
||||||
AccountManager manager = AccountManager.get(context);
|
// only enabled for Jelly Bean because we need some newer methods in our sync adapter
|
||||||
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
if (accounts == null || accounts.length == 0) {
|
AccountManager manager = AccountManager.get(context);
|
||||||
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
|
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||||
if (manager.addAccountExplicitly(account, null, null)) {
|
if (accounts == null || accounts.length == 0) {
|
||||||
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
|
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
|
||||||
} else {
|
if (manager.addAccountExplicitly(account, null, null)) {
|
||||||
Log.e(Constants.TAG, "Adding account failed!");
|
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
|
||||||
|
} else {
|
||||||
|
Log.e(Constants.TAG, "Adding account failed!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.helper;
|
|||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.content.ContentProviderOperation;
|
import android.content.ContentProviderOperation;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
@ -252,6 +253,7 @@ public class ContactHelper {
|
|||||||
return new ArrayList<String>(names);
|
return new ArrayList<String>(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
public static Uri dataUriFromContactUri(Context context, Uri contactUri) {
|
public static Uri dataUriFromContactUri(Context context, Uri contactUri) {
|
||||||
Cursor contactMasterKey = context.getContentResolver().query(contactUri,
|
Cursor contactMasterKey = context.getContentResolver().query(contactUri,
|
||||||
new String[]{ContactsContract.Data.DATA2}, null, null, null, null);
|
new String[]{ContactsContract.Data.DATA2}, null, null, null, null);
|
||||||
@ -367,6 +369,7 @@ public class ContactHelper {
|
|||||||
*
|
*
|
||||||
* @return raw contact id or -1 if not found
|
* @return raw contact id or -1 if not found
|
||||||
*/
|
*/
|
||||||
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
private static int findRawContactId(ContentResolver resolver, String fingerprint) {
|
private static int findRawContactId(ContentResolver resolver, String fingerprint) {
|
||||||
int rawContactId = -1;
|
int rawContactId = -1;
|
||||||
Cursor raw = resolver.query(ContactsContract.RawContacts.CONTENT_URI, ID_PROJECTION,
|
Cursor raw = resolver.query(ContactsContract.RawContacts.CONTENT_URI, ID_PROJECTION,
|
||||||
|
Loading…
Reference in New Issue
Block a user