ContactHelper can read email addresses from contact list

This commit is contained in:
mar-v-in 2014-05-26 20:24:13 +02:00
parent 13d4a6d902
commit 7865b92285
2 changed files with 22 additions and 0 deletions

View File

@ -53,6 +53,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!-- android:allowBackup="false": Don't allow backup over adb backup or other apps! -->
<application

View File

@ -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);
}
}