android.provider.ContactsContract.CommonDataKinds.Email Java Examples

The following examples show how to use android.provider.ContactsContract.CommonDataKinds.Email. 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: QuickContactBadge.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    // If contact has been assigned, mExtras should no longer be null, but do a null check
    // anyway just in case assignContactFromPhone or Email was called with a null bundle or
    // wasn't assigned previously.
    final Bundle extras = (mExtras == null) ? new Bundle() : mExtras;
    if (mContactUri != null) {
        QuickContact.showQuickContact(getContext(), QuickContactBadge.this, mContactUri,
                mExcludeMimes, mPrioritizedMimeType);
    } else if (mContactEmail != null && mQueryHandler != null) {
        extras.putString(EXTRA_URI_CONTENT, mContactEmail);
        mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras,
                Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)),
                EMAIL_LOOKUP_PROJECTION, null, null, null);
    } else if (mContactPhone != null && mQueryHandler != null) {
        extras.putString(EXTRA_URI_CONTENT, mContactPhone);
        mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP_AND_TRIGGER, extras,
                Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone),
                PHONE_LOOKUP_PROJECTION, null, null, null);
    } else {
        // If a contact hasn't been assigned, don't react to click.
        return;
    }
}
 
Example #2
Source File: ContactBadge.java    From Android-ContactPicker with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    // If contact has been assigned, mExtras should no longer be null, but do a null check
    // anyway just in case assignContactFromPhone or Email was called with a null bundle or
    // wasn't assigned previously.
    final Bundle extras = (mExtras == null) ? new Bundle() : mExtras;
    if (mContactUri != null) {
        QuickContact.showQuickContact(getContext(), ContactBadge.this, mContactUri, QuickContact.MODE_LARGE, mExcludeMimes);
    } else if (mContactEmail != null && mQueryHandler != null) {
        extras.putString(Constants.EXTRA_URI_CONTENT, mContactEmail);
        mQueryHandler.startQuery(Constants.TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras,
                Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)),
                EMAIL_LOOKUP_PROJECTION, null, null, null, mContactQueryHandlerCallback);
    } else if (mContactPhone != null && mQueryHandler != null) {
        extras.putString(Constants.EXTRA_URI_CONTENT, mContactPhone);
        mQueryHandler.startQuery(Constants.TOKEN_PHONE_LOOKUP_AND_TRIGGER, extras,
                Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone),
                PHONE_LOOKUP_PROJECTION, null, null, null, mContactQueryHandlerCallback);
    } else {
        // If a contact hasn't been assigned, don't react to click.
        return;
    }
}
 
Example #3
Source File: SelectContactModule.java    From react-native-select-contact with MIT License 5 votes vote down vote up
private void addEmailEntry(WritableArray emails, Cursor cursor, Activity activity) {
    String emailAddress = cursor.getString(cursor.getColumnIndex(Email.ADDRESS));
    int emailType = cursor.getInt(cursor.getColumnIndex(Email.TYPE));
    String emailLabel = cursor.getString(cursor.getColumnIndex(Email.LABEL));
    CharSequence typeLabel = Email.getTypeLabel(activity.getResources(), emailType, emailLabel);

    WritableMap emailEntry = Arguments.createMap();
    emailEntry.putString("address", emailAddress);
    emailEntry.putString("type", String.valueOf(typeLabel));

    emails.pushMap(emailEntry);
}
 
Example #4
Source File: QuickContactBadge.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Assign a contact based on an email address. This should only be used when
 * the contact's URI is not available, as an extra query will have to be
 * performed to lookup the URI based on the email.

 @param emailAddress The email address of the contact.
 @param lazyLookup If this is true, the lookup query will not be performed
 until this view is clicked.
 @param extras A bundle of extras to populate the contact edit page with if the contact
 is not found and the user chooses to add the email address to an existing contact or
 create a new contact. Uses the same string constants as those found in
 {@link android.provider.ContactsContract.Intents.Insert}
*/

public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) {
    mContactEmail = emailAddress;
    mExtras = extras;
    if (!lazyLookup && mQueryHandler != null) {
        mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null,
                Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)),
                EMAIL_LOOKUP_PROJECTION, null, null, null);
    } else {
        mContactUri = null;
        onContactUriChanged();
    }
}
 
Example #5
Source File: ContactEmailAdapter.java    From Contacts with MIT License 5 votes vote down vote up
@Override
public void bindData(View view, BaseType data, int position)
{
	final TitleTextHolder holder = (TitleTextHolder) getHolder(view);

	final ContactEmail email = ((ContactEmail) data);

	holder.primaryText.setText(email.email);
	
	Email.getTypeLabel(holder.primaryText.getResources(), email.type, email.label);
}
 
Example #6
Source File: CommonUtils.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
/**
 * 往手机通讯录插入联系人
 *
 * @param ct
 * @param name
 * @param tel
 * @param email
 */
public static void insertContact(Context ct, String name, String tel, String email) {
    ContentValues values = new ContentValues();
    // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
    Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI, values);
    long rawContactId = ContentUris.parseId(rawContactUri);
    // 往data表入姓名数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型
        values.put(StructuredName.GIVEN_NAME, name);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入电话数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Phone.NUMBER, tel);
        values.put(Phone.TYPE, Phone.TYPE_MOBILE);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入Email数据
    if (!TextUtils.isEmpty(email)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Email.DATA, email);
        values.put(Email.TYPE, Email.TYPE_WORK);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
}
 
Example #7
Source File: HoneycombMR1Util.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Get the DATA_PROJECTION for ContactPicker and PhoneNumberPicker.
 */
public static String[] getDataProjection() {
  String[] dataProjection = {
    Data.MIMETYPE,
    Email.ADDRESS,
    Email.TYPE,
    Phone.NUMBER,
    Phone.TYPE,
  };
  return dataProjection;
}
 
Example #8
Source File: HoneycombMR1Util.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Get the NEW_PROJECTION for EmailAddressAdapter.
 */
public static String[] getEmailAdapterProjection() {
  String[] emailAdapterProjection = {
    Data._ID,
    Data.DISPLAY_NAME,
    Email.ADDRESS,
    Data.MIMETYPE,
  };
  return emailAdapterProjection;
}
 
Example #9
Source File: ContactOperations.java    From tindroid with Apache License 2.0 5 votes vote down vote up
/**
 * Updates contact's email
 *
 * @param email email id of the sample SyncAdapter user
 * @param uri   Uri for the existing raw contact to be updated
 * @return instance of ContactOperations
 */
ContactOperations updateEmail(final String email, final String existingEmail, final Uri uri) {
    mValues.clear();
    if (!TextUtils.equals(existingEmail, email)) {
        mValues.put(Email.ADDRESS, email);
        addUpdateOp(uri);
    }
    return this;
}
 
Example #10
Source File: HoneycombMR1Util.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the dataCursor for ContactPicker and PhoneNumberPicker (used for Email and Phone).
 */
public static Cursor getDataCursor(String id, Activity activityContext, String[] dataProjection) {
  Cursor dataCursor = activityContext.getContentResolver().query(
      Data.CONTENT_URI,
      dataProjection,
      Data.CONTACT_ID + "=? AND (" + Data.MIMETYPE + "=? OR " + Data.MIMETYPE + "=?)",
      new String[] {id, Phone.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE},
      null);
  return dataCursor;
}
 
Example #11
Source File: ContactOperations.java    From tindroid with Apache License 2.0 5 votes vote down vote up
/**
 * Adds an email
 *
 * @param email address we're adding
 * @return instance of ContactOperations
 */
ContactOperations addEmail(final String email) {
    mValues.clear();
    if (!TextUtils.isEmpty(email)) {
        mValues.put(Email.ADDRESS, email);
        mValues.put(Email.TYPE, Email.TYPE_OTHER);
        mValues.put(Email.MIMETYPE, Email.CONTENT_ITEM_TYPE);
        addInsertOp();
    }
    return this;
}
 
Example #12
Source File: DeviceContactMatcher.java    From buddycloud-android with Apache License 2.0 4 votes vote down vote up
private List<String> getOtherEmailAddresses(ContentResolver contentResolver) {
	return getContactData(contentResolver, Email.CONTENT_URI, Email.DATA);
}
 
Example #13
Source File: Queries.java    From ChipsLibrary with Apache License 2.0 4 votes vote down vote up
@Override
public CharSequence getTypeLabel(final Resources res,final int type,final CharSequence label)
  {
  return Email.getTypeLabel(res,type,label);
  }
 
Example #14
Source File: ContactDetailFragment.java    From Contacts with MIT License 4 votes vote down vote up
@Override
protected Contact doInBackground(Cursor... params)
{
	mContact = new Contact();
	mContact.setLookupKey(mLookupKey);

	Cursor cursor = params[0];

	if (cursor != null && !cursor.isClosed())
	{
		while (cursor.moveToNext())
		{
			long id = cursor.getLong(0);
			String name = cursor.getString(1);
			String firstName = cursor.getString(2);
			String lastName = cursor.getString(3);
			String photo = cursor.getString(4);
			String photoThumb = cursor.getString(5);
			int starred = cursor.getInt(6);

			mContact.setId(id);

			if (name != null)
				mContact.setName(name);

			if (firstName != null)
				mContact.setFirstName(firstName);

			if (lastName != null)
				mContact.setLastName(lastName);

			if (photo != null)
				mContact.setPhoto(photo);

			if (photoThumb != null)
				mContact.setPhotoThumb(photoThumb);

			mContact.setStarred(starred == 1);
		}

		cursor.close();
	}

	String[] projection = { Phone.TYPE, Phone.NORMALIZED_NUMBER, Phone.LABEL, Phone.NUMBER };
	String selection = Phone.LOOKUP_KEY + " = ?";
	String[] parameters = new String[] { mLookupKey };
	Cursor phones = getActivity().getContentResolver().query(Phone.CONTENT_URI, projection, selection, parameters, null);

	while (phones.moveToNext())
	{
		if (phones.getString(1) != null)
			mContact.addPhoneNumber(phones.getInt(0), phones.getString(1), phones.getString(2));
		else
			mContact.addPhoneNumber(phones.getInt(0), phones.getString(3), phones.getString(2));
	}

	phones.close();

	// Same process for the names
	projection = new String[] { Email.TYPE, Email.ADDRESS };
	selection = Email.LOOKUP_KEY + " = ?";
	parameters = new String[] { mLookupKey };

	Cursor emails = getActivity().getContentResolver().query(Email.CONTENT_URI, projection, selection, parameters, null);

	while (emails.moveToNext())
	{
		mContact.addEmailAddress(emails.getInt(0), emails.getString(1));
	}

	return mContact;
}
 
Example #15
Source File: Queries.java    From talk-android with MIT License 4 votes vote down vote up
@Override
public CharSequence getTypeLabel(Resources res, int type, CharSequence label) {
    return Email.getTypeLabel(res, type, label);
}
 
Example #16
Source File: HoneycombMR1Util.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Get Email.ADDRESS for EmailAddressAdapter.
 */
public static String getEmailAddress() {
  return Email.ADDRESS;
}
 
Example #17
Source File: HoneycombMR1Util.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Get Email.CONTENT_ITEM_TYPE.
 */
public static String getEmailType() {
  return Email.CONTENT_ITEM_TYPE;
}
 
Example #18
Source File: HoneycombMR1Util.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
public static int getEmailIndex(Cursor dataCursor) {
  return dataCursor.getColumnIndex(Email.ADDRESS);
}
 
Example #19
Source File: PhoneContact.java    From XERUNG with Apache License 2.0 4 votes vote down vote up
public static ArrayList<PhoneContact> fetch(ContactFilter filter, Context context)
{
	if(_all == null || _emailable == null || _phoneable == null)
	{
		ContentResolver contResv = context.getContentResolver();
		
		ArrayList<PhoneContact> allContacts = new ArrayList<PhoneContact>();
		ArrayList<PhoneContact> phoneableContacts = new ArrayList<PhoneContact>();
		ArrayList<PhoneContact> emailableContacts = new ArrayList<PhoneContact>();
		
	    Cursor cursor = contResv.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
	    if(cursor.moveToFirst())
	    {
	        do
	        {
	        	PhoneContact contact = new PhoneContact();

	        	contact.name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));       
	        	contact.id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

	            Cursor emails = contResv.query(Email.CONTENT_URI,null,Email.CONTACT_ID + " = " + contact.id, null, null);
	            while (emails.moveToNext()) 
	            { 
	            	contact.email = emails.getString(emails.getColumnIndex(Email.DATA));
	                break;
	            }
	            emails.close();

	            if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
	            {
	                Cursor pCur = contResv.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{ contact.id }, null);
	                while (pCur.moveToNext()) 
	                {
	                	contact.phone = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
	                    break;
	                }
	                pCur.close();
	            }

	            if(contact.phone.length() > 0)
	            {
	            	phoneableContacts.add(contact);
	            }
	            if(contact.email.length() > 0)
	            {
	            	emailableContacts.add(contact);
	            }
	            allContacts.add(contact);

	        } while (cursor.moveToNext()) ;
	    } 

	    _phoneable = phoneableContacts;
	    _all = allContacts;
	    _emailable = emailableContacts;
	    cursor.close(); 
	}
	
	switch(filter)
	{
		case All:
		return _all;
		
		case Email:
		return _emailable;
		
		case Phone:
		return _phoneable;
	}
	
	return _all;
}
 
Example #20
Source File: PhoneContact.java    From XERUNG with Apache License 2.0 4 votes vote down vote up
public static ArrayList<PhoneContact> fetch(ContactFilter filter, Context context)
{
	if(_all == null || _emailable == null || _phoneable == null)
	{
		ContentResolver contResv = context.getContentResolver();
		
		ArrayList<PhoneContact> allContacts = new ArrayList<PhoneContact>();
		ArrayList<PhoneContact> phoneableContacts = new ArrayList<PhoneContact>();
		ArrayList<PhoneContact> emailableContacts = new ArrayList<PhoneContact>();
		
	    Cursor cursor = contResv.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
	    if(cursor.moveToFirst())
	    {
	        do
	        {
	        	PhoneContact contact = new PhoneContact();

	        	contact.name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));       
	        	contact.id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

	            Cursor emails = contResv.query(Email.CONTENT_URI,null,Email.CONTACT_ID + " = " + contact.id, null, null);
	            while (emails.moveToNext()) 
	            { 
	            	contact.email = emails.getString(emails.getColumnIndex(Email.DATA));
	                break;
	            }
	            emails.close();

	            if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
	            {
	                Cursor pCur = contResv.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{ contact.id }, null);
	                while (pCur.moveToNext()) 
	                {
	                	contact.phone = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
	                    break;
	                }
	                pCur.close();
	            }

	            if(contact.phone.length() > 0)
	            {
	            	phoneableContacts.add(contact);
	            }
	            if(contact.email.length() > 0)
	            {
	            	emailableContacts.add(contact);
	            }
	            allContacts.add(contact);

	        } while (cursor.moveToNext()) ;
	    } 

	    _phoneable = phoneableContacts;
	    _all = allContacts;
	    _emailable = emailableContacts;
	    cursor.close(); 
	}
	
	switch(filter)
	{
		case All:
		return _all;
		
		case Email:
		return _emailable;
		
		case Phone:
		return _phoneable;
	}
	
	return _all;
}
 
Example #21
Source File: ContactListProvider.java    From PrivacyStreams with Apache License 2.0 4 votes vote down vote up
private void getContactList() {
        ContentResolver contentResolver = this.getContext().getContentResolver();

        Cursor contactCur = contentResolver.query(
                ContactsContract.Contacts.CONTENT_URI,
                null,
                null,
                null,
                null
        );

        if (contactCur != null && contactCur.getCount() > 0) {
            contactCur.moveToFirst();
            while (!contactCur.isAfterLast()) {
                String _id = contactCur.getString(contactCur.getColumnIndex(ContactsContract.Data._ID));
                String name = contactCur.getString(contactCur.getColumnIndex(Phone.DISPLAY_NAME));

                List<String> phones = new ArrayList<>();
                Cursor phoneCur = contentResolver.query(
                        Phone.CONTENT_URI,
                        null,
                        Phone.CONTACT_ID + " = " + _id,
                        null,
                        null);
                if (phoneCur != null) {
                    while (phoneCur.moveToNext()) {
                        String number = phoneCur.getString(phoneCur.getColumnIndex(Phone.NUMBER));
                        phones.add(CommunicationUtils.normalizePhoneNumber(number));
//                    int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));
                    }
                    phoneCur.close();
                }

                List<String> emails = new ArrayList<>();
                Cursor emailCur = contentResolver.query(
                        Email.CONTENT_URI,
                        null,
                        Email.CONTACT_ID + " = " + _id,
                        null,
                        null);
                if (emailCur != null) {
                    while (emailCur.moveToNext()) {
                        String email = emailCur.getString(emailCur.getColumnIndex(Email.ADDRESS));
                        emails.add(email);
                    }
                    emailCur.close();
                }

                Contact contact = new Contact(_id, name, phones, emails);
                this.output(contact);

                contactCur.moveToNext();
            }
        }

        if (contactCur != null) {
            contactCur.close();
        }

        this.finish();
    }
 
Example #22
Source File: ContactBadge.java    From Android-ContactPicker with Apache License 2.0 3 votes vote down vote up
/**
 * Assign a contact based on an email address. This should only be used when
 * the contact's URI is not available, as an extra query will have to be
 * performed to lookup the URI based on the email.
 *
 * @param emailAddress The email address of the contact.
 * @param lazyLookup   If this is true, the lookup query will not be performed until this view is
 *                     clicked.
 * @param extras       A bundle of extras to populate the contact edit page with if the contact is not
 *                     found and the user chooses to add the email address to an existing contact or
 *                     create a new contact. Uses the same string constants as those found in
 *                     {@link android.provider.ContactsContract.Intents.Insert}
 */
public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) {
    mContactEmail = emailAddress;
    mExtras = extras;
    if (!lazyLookup && mQueryHandler != null) {
        mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null,
                Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)),
                EMAIL_LOOKUP_PROJECTION, null, null, null, mContactQueryHandlerCallback);
    } else {
        mContactUri = null;
        onContactUriChanged();
    }
}