Java Code Examples for android.provider.ContactsContract.PhoneLookup#DISPLAY_NAME

The following examples show how to use android.provider.ContactsContract.PhoneLookup#DISPLAY_NAME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactAccessor.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ContactIdentityManagerICS.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: ContactAccessor.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: PhoneUtilEclair.java    From DumbphoneAssistant with GNU General Public License v2.0 4 votes vote down vote up
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;
}