下面列出了android.provider.ContactsContract.PhoneLookup#DISPLAY_NAME 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public boolean isSystemContact(Context context, String number) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{PhoneLookup.DISPLAY_NAME, PhoneLookup.LOOKUP_KEY,
PhoneLookup._ID, PhoneLookup.NUMBER};
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
return true;
}
} finally {
if (cursor != null) cursor.close();
}
return false;
}
@Override
public Uri getSelfIdentityUri() {
String[] PROJECTION = new String[] {
PhoneLookup.DISPLAY_NAME,
PhoneLookup.LOOKUP_KEY,
PhoneLookup._ID,
};
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI,
PROJECTION, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
public Collection<ContactData> getContactsWithPush(Context context) {
final ContentResolver resolver = context.getContentResolver();
final String[] inProjection = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
final List<String> registeredAddresses = Stream.of(DatabaseFactory.getRecipientDatabase(context).getRegistered())
.map(Recipient::resolved)
.filter(r -> r.getE164().isPresent())
.map(Recipient::requireE164)
.toList();
final Collection<ContactData> lookupData = new ArrayList<>(registeredAddresses.size());
for (String registeredAddress : registeredAddresses) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(registeredAddress));
Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
try {
if (lookupCursor != null && lookupCursor.moveToFirst()) {
final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
contactData.numbers.add(new NumberData("TextSecure", registeredAddress));
lookupData.add(contactData);
}
} finally {
if (lookupCursor != null)
lookupCursor.close();
}
}
return lookupData;
}
public ArrayList<Contact> get() {
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] {
PhoneLookup._ID,
PhoneLookup.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.LABEL,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
String[] simTypesQueryParts = new String[simTypes.length];
Arrays.fill(simTypesQueryParts, ContactsContract.RawContacts.ACCOUNT_TYPE + " <> ?");
String simTypesQuery = TextUtils.join(" AND ", simTypesQueryParts);
String selection = ContactsContract.RawContacts.ACCOUNT_TYPE + " IS NULL OR (" + simTypesQuery + ")";
String[] selectionArgs = simTypes;
Cursor results = resolver.query(
uri,
projection,
selection,
selectionArgs,
null
);
// create array of Phone contacts and fill it
final ArrayList<Contact> phoneContacts = new ArrayList<>();
int indexId = results.getColumnIndex(PhoneLookup._ID);
int indexName = results.getColumnIndex(PhoneLookup.DISPLAY_NAME);
int indexType = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
int indexLabel = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL);
int indexNumber = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
while (results.moveToNext()) {
int type = results.getInt(indexType);
String custom = results.getString(indexLabel);
final Contact phoneContact = new Contact(
results.getString(indexId),
results.getString(indexName),
results.getString(indexNumber),
(String) Phone.getTypeLabel(this.activity.getResources(), type, custom)
);
phoneContacts.add(phoneContact);
}
results.close();
return phoneContacts;
}