Java Code Examples for android.provider.ContactsContract.Contacts#getLookupUri()

The following examples show how to use android.provider.ContactsContract.Contacts#getLookupUri() . 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: 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 2
Source File: RecipientProvider.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private @NonNull RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, @NonNull String number) {
  Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[]{recipientId});
  MaterialColor                   color       = preferences.isPresent() ? preferences.get().getColor() : null;
  Uri                             uri         = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

  try (Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION, null, null, null)) {
    if (cursor != null && cursor.moveToFirst()) {
      final String resultNumber = cursor.getString(3);
      if (resultNumber != null) {
        Uri          contactUri   = Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
        String       name         = resultNumber.equals(cursor.getString(0)) ? null : cursor.getString(0);
        ContactPhoto contactPhoto = ContactPhotoFactory.getContactPhoto(context,
                                                                        Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""),
                                                                        name);

        return new RecipientDetails(cursor.getString(0), resultNumber, contactUri, contactPhoto, color);
      } else {
        Log.w(TAG, "resultNumber is null");
      }
    }
  } catch (SecurityException se) {
    Log.w(TAG, se);
  }

  if (STATIC_DETAILS.containsKey(number)) return STATIC_DETAILS.get(number);
  else                                    return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color);
}
 
Example 3
Source File: ContactDetailFragment.java    From Contacts with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
	if (item.getItemId() == R.id.menu_starred)
	{
		ContentValues values = new ContentValues();
		values.put(Contacts.STARRED, mContact.isStarred() ? 0 : 1);
		mContact.setStarred(!mContact.isStarred());

		getActivity().getContentResolver().update(Contacts.CONTENT_URI, values, Contacts.LOOKUP_KEY + "= ?",
				new String[] { mContact.getLookupKey() });
		getActivity().invalidateOptionsMenu();

		return true;
	}
	else if (item.getItemId() == R.id.menu_edit)
	{
		Uri uri = Contacts.getLookupUri(mContact.getId(), mContact.getLookupKey());

		Intent intent = new Intent(Intent.ACTION_EDIT);
		intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE);
		intent.putExtra("finishActivityOnSaveCompleted", true);

		startActivity(intent);
	}
	else if (item.getItemId() == R.id.menu_delete)
	{
		AlertUtil.showAlert(getActivity(), AlertUtil.NONE, R.string.delete_dialog_message, R.string.ok, new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				deleteContact();
			}
		}, R.string.cancel, null);
	}

	return super.onOptionsItemSelected(item);
}
 
Example 4
Source File: ContactDetailFragment.java    From Contacts with MIT License 5 votes vote down vote up
private void deleteContact()
{
	Uri uri = Contacts.getLookupUri(mContact.getId(), mContact.getLookupKey());
	getActivity().getContentResolver().delete(uri, null, null);

	if (listener != null)
		listener.onContactDeleted(mLookupKey);
}