diff options
author | mar-v-in <github@rvin.mooo.com> | 2014-05-26 20:24:13 +0200 |
---|---|---|
committer | mar-v-in <github@rvin.mooo.com> | 2014-05-26 20:24:13 +0200 |
commit | 7865b92285893ddb87fa8351d724d09d0a1eb781 (patch) | |
tree | 6ceac8dbcea498bf32120bf63abe5f84e7889f96 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java | |
parent | 13d4a6d902d61a0a85db3bdc07996b317f5ecaad (diff) | |
download | open-keychain-7865b92285893ddb87fa8351d724d09d0a1eb781.tar.gz open-keychain-7865b92285893ddb87fa8351d724d09d0a1eb781.tar.bz2 open-keychain-7865b92285893ddb87fa8351d724d09d0a1eb781.zip |
ContactHelper can read email addresses from contact list
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java index a92ea5408..583543c4a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java @@ -19,7 +19,10 @@ package org.sufficientlysecure.keychain.helper; import android.accounts.Account; import android.accounts.AccountManager; +import android.content.ContentResolver; import android.content.Context; +import android.database.Cursor; +import android.provider.ContactsContract; import android.util.Patterns; import java.util.ArrayList; @@ -39,4 +42,22 @@ public class ContactHelper { } return new ArrayList<String>(emailSet); } + + public static List<String> getContactMails(Context context) { + ContentResolver resolver = context.getContentResolver(); + Cursor mailCursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, + new String[]{ContactsContract.CommonDataKinds.Email.DATA}, + null, null, null); + if (mailCursor == null) return null; + + Set<String> mails = new HashSet<String>(); + while (mailCursor.moveToNext()) { + String email = mailCursor.getString(0); + if (email != null) { + mails.add(email); + } + } + mailCursor.close(); + return new ArrayList<String>(mails); + } } |